Skip to content

Commit 0683b53

Browse files
committed
signal: Deliver all of the siginfo perf data in _perf
Don't abuse si_errno and deliver all of the perf data in _perf member of siginfo_t. Note: The data field in the perf data structures in a u64 to allow a pointer to be encoded without needed to implement a 32bit and 64bit version of the same structure. There already exists a 32bit and 64bit versions siginfo_t, and the 32bit version can not include a 64bit member as it only has 32bit alignment. So unsigned long is used in siginfo_t instead of a u64 as unsigned long can encode a pointer on all architectures linux supports. v1: https://lkml.kernel.org/r/m11rarqqx2.fsf_-_@fess.ebiederm.org v2: https://lkml.kernel.org/r/20210503203814.25487-10-ebiederm@xmission.com v3: https://lkml.kernel.org/r/20210505141101.11519-11-ebiederm@xmission.com Link: https://lkml.kernel.org/r/20210517195748.8880-4-ebiederm@xmission.com Reviewed-by: Marco Elver <elver@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent af5eeab commit 0683b53

9 files changed

Lines changed: 41 additions & 25 deletions

File tree

arch/m68k/kernel/signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ static inline void siginfo_build_tests(void)
623623
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x12);
624624

625625
/* _sigfault._perf */
626-
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10);
626+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_data) != 0x10);
627+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_type) != 0x14);
627628

628629
/* _sigpoll */
629630
BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x0c);

arch/x86/kernel/signal_compat.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ static inline void signal_compat_build_tests(void)
141141
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
142142
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
143143

144-
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x18);
145-
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf) != 0x10);
144+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_data) != 0x18);
145+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_type) != 0x20);
146+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_data) != 0x10);
147+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_type) != 0x14);
146148

147149
CHECK_CSI_OFFSET(_sigpoll);
148150
CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));

fs/signalfd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
134134
break;
135135
case SIL_PERF_EVENT:
136136
new.ssi_addr = (long) kinfo->si_addr;
137-
new.ssi_perf = kinfo->si_perf;
137+
new.ssi_perf_type = kinfo->si_perf_type;
138+
new.ssi_perf_data = kinfo->si_perf_data;
138139
break;
139140
case SIL_CHLD:
140141
new.ssi_pid = kinfo->si_pid;

include/linux/compat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ typedef struct compat_siginfo {
236236
u32 _pkey;
237237
} _addr_pkey;
238238
/* used when si_code=TRAP_PERF */
239-
compat_ulong_t _perf;
239+
struct {
240+
compat_ulong_t _data;
241+
u32 _type;
242+
} _perf;
240243
};
241244
} _sigfault;
242245

include/uapi/asm-generic/siginfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ union __sifields {
9191
__u32 _pkey;
9292
} _addr_pkey;
9393
/* used when si_code=TRAP_PERF */
94-
unsigned long _perf;
94+
struct {
95+
unsigned long _data;
96+
__u32 _type;
97+
} _perf;
9598
};
9699
} _sigfault;
97100

@@ -154,7 +157,8 @@ typedef struct siginfo {
154157
#define si_lower _sifields._sigfault._addr_bnd._lower
155158
#define si_upper _sifields._sigfault._addr_bnd._upper
156159
#define si_pkey _sifields._sigfault._addr_pkey._pkey
157-
#define si_perf _sifields._sigfault._perf
160+
#define si_perf_data _sifields._sigfault._perf._data
161+
#define si_perf_type _sifields._sigfault._perf._type
158162
#define si_band _sifields._sigpoll._band
159163
#define si_fd _sifields._sigpoll._fd
160164
#define si_call_addr _sifields._sigsys._call_addr

include/uapi/linux/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ struct perf_event_attr {
464464

465465
/*
466466
* User provided data if sigtrap=1, passed back to user via
467-
* siginfo_t::si_perf, e.g. to permit user to identify the event.
467+
* siginfo_t::si_perf_data, e.g. to permit user to identify the event.
468468
*/
469469
__u64 sig_data;
470470
};

include/uapi/linux/signalfd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct signalfd_siginfo {
3939
__s32 ssi_syscall;
4040
__u64 ssi_call_addr;
4141
__u32 ssi_arch;
42-
__u32 __pad3;
43-
__u64 ssi_perf;
42+
__u32 ssi_perf_type;
43+
__u64 ssi_perf_data;
4444

4545
/*
4646
* Pad strcture to 128 bytes. Remember to update the

kernel/signal.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)
17681768
struct kernel_siginfo info;
17691769

17701770
clear_siginfo(&info);
1771-
info.si_signo = SIGTRAP;
1772-
info.si_errno = type;
1773-
info.si_code = TRAP_PERF;
1774-
info.si_addr = addr;
1775-
info.si_perf = sig_data;
1771+
info.si_signo = SIGTRAP;
1772+
info.si_errno = 0;
1773+
info.si_code = TRAP_PERF;
1774+
info.si_addr = addr;
1775+
info.si_perf_data = sig_data;
1776+
info.si_perf_type = type;
1777+
17761778
return force_sig_info(&info);
17771779
}
17781780

@@ -3356,7 +3358,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,
33563358
break;
33573359
case SIL_PERF_EVENT:
33583360
to->si_addr = ptr_to_compat(from->si_addr);
3359-
to->si_perf = from->si_perf;
3361+
to->si_perf_data = from->si_perf_data;
3362+
to->si_perf_type = from->si_perf_type;
33603363
break;
33613364
case SIL_CHLD:
33623365
to->si_pid = from->si_pid;
@@ -3432,7 +3435,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,
34323435
break;
34333436
case SIL_PERF_EVENT:
34343437
to->si_addr = compat_ptr(from->si_addr);
3435-
to->si_perf = from->si_perf;
3438+
to->si_perf_data = from->si_perf_data;
3439+
to->si_perf_type = from->si_perf_type;
34363440
break;
34373441
case SIL_CHLD:
34383442
to->si_pid = from->si_pid;
@@ -4615,7 +4619,8 @@ static inline void siginfo_buildtime_checks(void)
46154619
CHECK_OFFSET(si_lower);
46164620
CHECK_OFFSET(si_upper);
46174621
CHECK_OFFSET(si_pkey);
4618-
CHECK_OFFSET(si_perf);
4622+
CHECK_OFFSET(si_perf_data);
4623+
CHECK_OFFSET(si_perf_type);
46194624

46204625
/* sigpoll */
46214626
CHECK_OFFSET(si_band);

tools/testing/selftests/perf_events/sigtrap_threads.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static struct {
4343
siginfo_t first_siginfo; /* First observed siginfo_t. */
4444
} ctx;
4545

46-
/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */
46+
/* Unique value to check si_perf_data is correctly set from perf_event_attr::sig_data. */
4747
#define TEST_SIG_DATA(addr) (~(unsigned long)(addr))
4848

4949
static struct perf_event_attr make_event_attr(bool enabled, volatile void *addr)
@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)
164164
EXPECT_EQ(ctx.signal_count, NUM_THREADS);
165165
EXPECT_EQ(ctx.tids_want_signal, 0);
166166
EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
167-
EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
168-
EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
167+
EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
168+
EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
169169

170170
/* Check enabled for parent. */
171171
ctx.iterate_on = 0;
@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)
183183
EXPECT_EQ(ctx.signal_count, NUM_THREADS);
184184
EXPECT_EQ(ctx.tids_want_signal, 0);
185185
EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
186-
EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
187-
EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
186+
EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
187+
EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
188188

189189
/* Check enabled for parent. */
190190
ctx.iterate_on = 0;
@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)
203203
EXPECT_EQ(ctx.signal_count, NUM_THREADS * ctx.iterate_on);
204204
EXPECT_EQ(ctx.tids_want_signal, 0);
205205
EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
206-
EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
207-
EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
206+
EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
207+
EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
208208
}
209209

210210
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)