]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
signal: Deliver all of the siginfo perf data in _perf
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 2 May 2021 22:28:31 +0000 (17:28 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 5 May 2021 17:49:08 +0000 (12:49 -0500)
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
Link: https://lkml.kernel.org/r/20210505141101.11519-11-ebiederm@xmission.com
Reviewed-by: Marco Elver <elver@google.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
12 files changed:
arch/arm/kernel/signal.c
arch/arm64/kernel/signal.c
arch/arm64/kernel/signal32.c
arch/sparc/kernel/signal32.c
arch/sparc/kernel/signal_64.c
arch/x86/kernel/signal_compat.c
fs/signalfd.c
include/linux/compat.h
include/uapi/asm-generic/siginfo.h
include/uapi/linux/signalfd.h
kernel/signal.c
tools/testing/selftests/perf_events/sigtrap_threads.c

index 643bcb0f091b823c03e1e5ea9ed35b579ad6d9af..f3800c0f428b75b8a42579b632f5c0fa8483ebb7 100644 (file)
@@ -757,7 +757,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb)      == 0x10);
 static_assert(offsetof(siginfo_t, si_lower)    == 0x14);
 static_assert(offsetof(siginfo_t, si_upper)    == 0x18);
 static_assert(offsetof(siginfo_t, si_pkey)     == 0x14);
-static_assert(offsetof(siginfo_t, si_perf)     == 0x10);
+static_assert(offsetof(siginfo_t, si_perf_data)        == 0x10);
+static_assert(offsetof(siginfo_t, si_perf_type)        == 0x14);
 static_assert(offsetof(siginfo_t, si_band)     == 0x0c);
 static_assert(offsetof(siginfo_t, si_fd)       == 0x10);
 static_assert(offsetof(siginfo_t, si_call_addr)        == 0x0c);
index ad4bd27fc044343554eb31709443fd81b3669c16..b3978b468bd45c2ae68805be9882f14601cc14fd 100644 (file)
@@ -1005,7 +1005,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb)    == 0x18);
 static_assert(offsetof(siginfo_t, si_lower)    == 0x20);
 static_assert(offsetof(siginfo_t, si_upper)    == 0x28);
 static_assert(offsetof(siginfo_t, si_pkey)     == 0x20);
-static_assert(offsetof(siginfo_t, si_perf)     == 0x18);
+static_assert(offsetof(siginfo_t, si_perf_data)        == 0x18);
+static_assert(offsetof(siginfo_t, si_perf_type)        == 0x20);
 static_assert(offsetof(siginfo_t, si_band)     == 0x10);
 static_assert(offsetof(siginfo_t, si_fd)       == 0x18);
 static_assert(offsetof(siginfo_t, si_call_addr)        == 0x10);
index ee6c7484e130949266de2070ced1238fdd4a21ef..d3be01c46becc54240713beb4c60d3f22c7bd9e4 100644 (file)
@@ -489,7 +489,8 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb)       == 0x10);
 static_assert(offsetof(compat_siginfo_t, si_lower)     == 0x14);
 static_assert(offsetof(compat_siginfo_t, si_upper)     == 0x18);
 static_assert(offsetof(compat_siginfo_t, si_pkey)      == 0x14);
-static_assert(offsetof(compat_siginfo_t, si_perf)      == 0x10);
+static_assert(offsetof(compat_siginfo_t, si_perf_data) == 0x10);
+static_assert(offsetof(compat_siginfo_t, si_perf_type) == 0x14);
 static_assert(offsetof(compat_siginfo_t, si_band)      == 0x0c);
 static_assert(offsetof(compat_siginfo_t, si_fd)                == 0x10);
 static_assert(offsetof(compat_siginfo_t, si_call_addr) == 0x0c);
index 5573722e34adc2df3e6abdf175e4c292659785df..4276b9e003ca5c265a60cea20568d5280552fb99 100644 (file)
@@ -778,6 +778,7 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb)       == 0x10);
 static_assert(offsetof(compat_siginfo_t, si_lower)     == 0x14);
 static_assert(offsetof(compat_siginfo_t, si_upper)     == 0x18);
 static_assert(offsetof(compat_siginfo_t, si_pkey)      == 0x14);
-static_assert(offsetof(compat_siginfo_t, si_perf)      == 0x10);
+static_assert(offsetof(compat_siginfo_t, si_perf_data) == 0x10);
+static_assert(offsetof(compat_siginfo_t, si_perf_type) == 0x14);
 static_assert(offsetof(compat_siginfo_t, si_band)      == 0x0c);
 static_assert(offsetof(compat_siginfo_t, si_fd)                == 0x10);
index a69a78984c367dfe73fce055d5d2106107c782d4..cea23cf95600673da588c5f32e61c71aba618978 100644 (file)
@@ -588,6 +588,7 @@ static_assert(offsetof(siginfo_t, si_addr_lsb)      == 0x18);
 static_assert(offsetof(siginfo_t, si_lower)    == 0x20);
 static_assert(offsetof(siginfo_t, si_upper)    == 0x28);
 static_assert(offsetof(siginfo_t, si_pkey)     == 0x20);
-static_assert(offsetof(siginfo_t, si_perf)     == 0x18);
+static_assert(offsetof(siginfo_t, si_perf_data)        == 0x18);
+static_assert(offsetof(siginfo_t, si_perf_type)        == 0x20);
 static_assert(offsetof(siginfo_t, si_band)     == 0x10);
 static_assert(offsetof(siginfo_t, si_fd)       == 0x14);
index c9601f092a1e5840444575867849bc3cb7884b58..b52407c56000e11c6a97a1d0b414e535cbc6b5dd 100644 (file)
@@ -147,8 +147,10 @@ static inline void signal_compat_build_tests(void)
        BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
        BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
 
-       BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x18);
-       BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf) != 0x10);
+       BUILD_BUG_ON(offsetof(siginfo_t, si_perf_data) != 0x18);
+       BUILD_BUG_ON(offsetof(siginfo_t, si_perf_type) != 0x20);
+       BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_data) != 0x10);
+       BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_type) != 0x14);
 
        CHECK_CSI_OFFSET(_sigpoll);
        CHECK_CSI_SIZE  (_sigpoll, 2*sizeof(int));
index 83130244f6530c5ef8d868a111433c545c209977..335ad39f3900a102a0846a0894453d6e7e6d6fbb 100644 (file)
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
                break;
        case SIL_FAULT_PERF_EVENT:
                new.ssi_addr = (long) kinfo->si_addr;
-               new.ssi_perf = kinfo->si_perf;
+               new.ssi_perf_type = kinfo->si_perf_type;
+               new.ssi_perf_data = kinfo->si_perf_data;
                break;
        case SIL_CHLD:
                new.ssi_pid    = kinfo->si_pid;
index 6af7bef15e94984b2529a505476961e16ca80ada..a27fffaae121ac132367b9050170cc8eb737b255 100644 (file)
@@ -236,7 +236,10 @@ typedef struct compat_siginfo {
                                        u32 _pkey;
                                } _addr_pkey;
                                /* used when si_code=TRAP_PERF */
-                               compat_ulong_t _perf;
+                               struct {
+                                       compat_ulong_t _data;
+                                       u32 _type;
+                               } _perf;
                        };
                } _sigfault;
 
index 3503282021aac9c32255e0ea692f8acaa8f9c9c4..3ba180f550d7cfc9cf78e4c7133047070625b11b 100644 (file)
@@ -96,7 +96,10 @@ union __sifields {
                                __u32 _pkey;
                        } _addr_pkey;
                        /* used when si_code=TRAP_PERF */
-                       unsigned long _perf;
+                       struct {
+                               unsigned long _data;
+                               __u32 _type;
+                       } _perf;
                };
        } _sigfault;
 
@@ -159,7 +162,8 @@ typedef struct siginfo {
 #define si_lower       _sifields._sigfault._addr_bnd._lower
 #define si_upper       _sifields._sigfault._addr_bnd._upper
 #define si_pkey                _sifields._sigfault._addr_pkey._pkey
-#define si_perf                _sifields._sigfault._perf
+#define si_perf_data   _sifields._sigfault._perf._data
+#define si_perf_type   _sifields._sigfault._perf._type
 #define si_band                _sifields._sigpoll._band
 #define si_fd          _sifields._sigpoll._fd
 #define si_call_addr   _sifields._sigsys._call_addr
index 7e333042c7e3a1e2522f7146c4eb7021fbe7c288..e78dddf433fcd91ef6fcf60b9396f7e21f8fe1c0 100644 (file)
@@ -39,8 +39,8 @@ struct signalfd_siginfo {
        __s32 ssi_syscall;
        __u64 ssi_call_addr;
        __u32 ssi_arch;
-       __u32 __pad3;
-       __u64 ssi_perf;
+       __u32 ssi_perf_type;
+       __u64 ssi_perf_data;
 
        /*
         * Pad strcture to 128 bytes. Remember to update the
index 49560ceac0488d79f3a20e3e32dadff88574d17b..7fec9d1c5b1119097fc4f4b3736fd3bf1557e57e 100644 (file)
@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)
        struct kernel_siginfo info;
 
        clear_siginfo(&info);
-       info.si_signo = SIGTRAP;
-       info.si_errno = type;
-       info.si_code  = TRAP_PERF;
-       info.si_addr  = addr;
-       info.si_perf  = sig_data;
+       info.si_signo     = SIGTRAP;
+       info.si_errno     = 0;
+       info.si_code      = TRAP_PERF;
+       info.si_addr      = addr;
+       info.si_perf_data = sig_data;
+       info.si_perf_type = type;
+
        return force_sig_info(&info);
 }
 
@@ -3380,7 +3382,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,
                break;
        case SIL_FAULT_PERF_EVENT:
                to->si_addr = ptr_to_compat(from->si_addr);
-               to->si_perf = from->si_perf;
+               to->si_perf_data = from->si_perf_data;
+               to->si_perf_type = from->si_perf_type;
                break;
        case SIL_CHLD:
                to->si_pid = from->si_pid;
@@ -3456,7 +3459,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,
                break;
        case SIL_FAULT_PERF_EVENT:
                to->si_addr = compat_ptr(from->si_addr);
-               to->si_perf = from->si_perf;
+               to->si_perf_data = from->si_perf_data;
+               to->si_perf_type = from->si_perf_type;
                break;
        case SIL_CHLD:
                to->si_pid    = from->si_pid;
@@ -4639,7 +4643,8 @@ static inline void siginfo_buildtime_checks(void)
        CHECK_OFFSET(si_lower);
        CHECK_OFFSET(si_upper);
        CHECK_OFFSET(si_pkey);
-       CHECK_OFFSET(si_perf);
+       CHECK_OFFSET(si_perf_data);
+       CHECK_OFFSET(si_perf_type);
 
        /* sigpoll */
        CHECK_OFFSET(si_band);
index 78ddf5e116254fc685dd508c0a4faa8e5990379c..fde123066a8c6a57549d4aca2faf7eb11e699ab1 100644 (file)
@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)
        EXPECT_EQ(ctx.signal_count, NUM_THREADS);
        EXPECT_EQ(ctx.tids_want_signal, 0);
        EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
-       EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
-       EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
+       EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
+       EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
 
        /* Check enabled for parent. */
        ctx.iterate_on = 0;
@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)
        EXPECT_EQ(ctx.signal_count, NUM_THREADS);
        EXPECT_EQ(ctx.tids_want_signal, 0);
        EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
-       EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
-       EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
+       EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
+       EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
 
        /* Check enabled for parent. */
        ctx.iterate_on = 0;
@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)
        EXPECT_EQ(ctx.signal_count, NUM_THREADS * ctx.iterate_on);
        EXPECT_EQ(ctx.tids_want_signal, 0);
        EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on);
-       EXPECT_EQ(ctx.first_siginfo.si_errno, PERF_TYPE_BREAKPOINT);
-       EXPECT_EQ(ctx.first_siginfo.si_perf, TEST_SIG_DATA(&ctx.iterate_on));
+       EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT);
+       EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on));
 }
 
 TEST_HARNESS_MAIN