Skip to content

Commit 08b1234

Browse files
executor: introduce __no_stack_protector and use it for guest code
When compiling the executor in syz-env-old, -fstack-protector may kick in and introduce global accesses that tools/check-syzos.sh reports. To prevent this, introduce the __no_stack_protector macro attribute that disable stack protection for the function in question, and use it for guest code. While at it, factor out some common definitions into common_kvm_syzos.h
1 parent 4e737d7 commit 08b1234

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

executor/common_kvm_amd64_syzos.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33

44
// This file provides guest code running inside the AMD64 KVM.
55

6+
#include "common_kvm_syzos.h"
67
#include "kvm.h"
78
#include <linux/kvm.h>
89
#include <stdbool.h>
910

10-
// Host will map the code in this section into the guest address space.
11-
#define GUEST_CODE __attribute__((section("guest")))
12-
13-
// Prevent function inlining. This attribute is applied to every guest_handle_* function,
14-
// making sure they remain small so that the compiler does not attempt to be too clever
15-
// (e.g. generate switch tables).
16-
#define noinline __attribute__((noinline))
17-
18-
// Start/end of the guest section.
19-
extern char *__start_guest, *__stop_guest;
20-
2111
// Compilers will eagerly try to transform the switch statement in guest_main()
2212
// into a jump table, unless the cases are sparse enough.
2313
// We use prime numbers multiplied by 10 to prevent this behavior.

executor/common_kvm_arm64_syzos.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33

44
// This file provides guest code running inside the ARM64 KVM.
55

6+
#include "common_kvm_syzos.h"
67
#include "kvm.h"
78
#include <linux/kvm.h>
89
#include <stdbool.h>
910

10-
// Host will map the code in this section into the guest address space.
11-
#define GUEST_CODE __attribute__((section("guest")))
12-
13-
// Prevent function inlining. This attribute is applied to every guest_handle_* function,
14-
// making sure they remain small so that the compiler does not attempt to be too clever
15-
// (e.g. generate switch tables).
16-
#define noinline __attribute__((noinline))
17-
18-
// Start/end of the guest section.
19-
extern char *__start_guest, *__stop_guest;
20-
2111
// Compilers will eagerly try to transform the switch statement in guest_main()
2212
// into a jump table, unless the cases are sparse enough.
2313
// We use prime numbers multiplied by 10 to prevent this behavior.
@@ -1201,7 +1191,8 @@ GUEST_CODE static void its_send_movall_cmd(uint64 cmdq_base, uint32 vcpu_id, uin
12011191
its_send_cmd(cmdq_base, &cmd);
12021192
}
12031193

1204-
GUEST_CODE static void its_send_invall_cmd(uint64 cmdq_base, uint32 collection_id)
1194+
GUEST_CODE static void
1195+
its_send_invall_cmd(uint64 cmdq_base, uint32 collection_id)
12051196
{
12061197
struct its_cmd_block cmd;
12071198
guest_memzero(&cmd, sizeof(cmd));

executor/common_kvm_syzos.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2025 syzkaller project authors. All rights reserved.
2+
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3+
4+
// Common SYZOS definitions.
5+
6+
// Prevent function inlining. This attribute is applied to every guest_handle_* function,
7+
// making sure they remain small so that the compiler does not attempt to be too clever
8+
// (e.g. generate switch tables).
9+
#define noinline __attribute__((noinline))
10+
11+
// __no_stack_protector disables -fstack-protector which may introduce unwanted global accesses.
12+
// TODO(glider): once syz-env-old migrates to GCC>11 we can just use
13+
// __attribute__((no_stack_protector)).
14+
#if defined(__clang__)
15+
// Clang supports the no_stack_protector attribute.
16+
#define __no_stack_protector __attribute__((no_stack_protector))
17+
#elif defined(__GNUC__)
18+
// The no_stack_protector attribute was introduced in GCC 11.1.
19+
#if __GNUC__ > 11
20+
#define __no_stack_protector __attribute__((no_stack_protector))
21+
#else
22+
// Fallback to the optimize attribute for older GCC versions.
23+
#define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
24+
#endif
25+
#else
26+
#define __no_stack_protector
27+
#endif
28+
29+
// Host will map the code in this section into the guest address space.
30+
#define GUEST_CODE __attribute__((section("guest"))) __no_stack_protector
31+
32+
// Start/end of the guest section.
33+
extern char *__start_guest, *__stop_guest;

0 commit comments

Comments
 (0)