diff mbox series

[1/3] sparc64: Add compile-time asserts for siginfo_t offsets

Message ID 20210429190734.624918-1-elver@google.com (mailing list archive)
State New, archived
Headers show
Series [1/3] sparc64: Add compile-time asserts for siginfo_t offsets | expand

Commit Message

Marco Elver April 29, 2021, 7:07 p.m. UTC
To help catch ABI breaks at compile-time, add compile-time assertions to
verify the siginfo_t layout. Unlike other architectures, sparc64 is
special, because it is one of few architectures requiring si_trapno.
ABI breaks around that field would only be caught here.

Link: https://lkml.kernel.org/r/m11rat9f85.fsf@fess.ebiederm.org
Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Marco Elver <elver@google.com>
---
 arch/sparc/kernel/signal32.c  | 34 ++++++++++++++++++++++++++++++++++
 arch/sparc/kernel/signal_64.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

Comments

Eric W. Biederman April 30, 2021, 5:42 p.m. UTC | #1
Marco Elver <elver@google.com> writes:

> To help catch ABI breaks at compile-time, add compile-time assertions to
> verify the siginfo_t layout. Unlike other architectures, sparc64 is
> special, because it is one of few architectures requiring si_trapno.
> ABI breaks around that field would only be caught here.

Arnd Bergman recently pointed out that we can move si_trapno into the
union and make it specific to a handful of signals.  Like we do other
items in the union.

Given that the code of perf_sigtrap is pretty much broken if si_trapno
needs to be filled out.  I think we should make that change before
we set this ABI in stone like this.

Otherwise this looks good.

Eric

> Link: https://lkml.kernel.org/r/m11rat9f85.fsf@fess.ebiederm.org
> Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
> Signed-off-by: Marco Elver <elver@google.com>
> ---
>  arch/sparc/kernel/signal32.c  | 34 ++++++++++++++++++++++++++++++++++
>  arch/sparc/kernel/signal_64.c | 33 +++++++++++++++++++++++++++++++++
>  2 files changed, 67 insertions(+)
>
> diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
> index e9695a06492f..778ed5c26d4a 100644
> --- a/arch/sparc/kernel/signal32.c
> +++ b/arch/sparc/kernel/signal32.c
> @@ -745,3 +745,37 @@ asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
>  out:
>  	return ret;
>  }
> +
> +/*
> + * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
> + * changes likely come with new fields that should be added below.
> + */
> +static_assert(NSIGILL	== 11);
> +static_assert(NSIGFPE	== 15);
> +static_assert(NSIGSEGV	== 9);
> +static_assert(NSIGBUS	== 5);
> +static_assert(NSIGTRAP	== 6);
> +static_assert(NSIGCHLD	== 6);
> +static_assert(NSIGSYS	== 2);
> +static_assert(offsetof(compat_siginfo_t, si_signo)	== 0x00);
> +static_assert(offsetof(compat_siginfo_t, si_errno)	== 0x04);
> +static_assert(offsetof(compat_siginfo_t, si_code)	== 0x08);
> +static_assert(offsetof(compat_siginfo_t, si_pid)	== 0x0c);
> +static_assert(offsetof(compat_siginfo_t, si_uid)	== 0x10);
> +static_assert(offsetof(compat_siginfo_t, si_tid)	== 0x0c);
> +static_assert(offsetof(compat_siginfo_t, si_overrun)	== 0x10);
> +static_assert(offsetof(compat_siginfo_t, si_status)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_utime)	== 0x18);
> +static_assert(offsetof(compat_siginfo_t, si_stime)	== 0x1c);
> +static_assert(offsetof(compat_siginfo_t, si_value)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_int)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_ptr)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_addr)	== 0x0c);
> +static_assert(offsetof(compat_siginfo_t, si_trapno)	== 0x10);
> +static_assert(offsetof(compat_siginfo_t, si_addr_lsb)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_lower)	== 0x18);
> +static_assert(offsetof(compat_siginfo_t, si_upper)	== 0x1c);
> +static_assert(offsetof(compat_siginfo_t, si_pkey)	== 0x18);
> +static_assert(offsetof(compat_siginfo_t, si_perf)	== 0x14);
> +static_assert(offsetof(compat_siginfo_t, si_band)	== 0x0c);
> +static_assert(offsetof(compat_siginfo_t, si_fd)		== 0x10);
> diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c
> index a0eec62c825d..c9bbf5f29078 100644
> --- a/arch/sparc/kernel/signal_64.c
> +++ b/arch/sparc/kernel/signal_64.c
> @@ -556,3 +556,36 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long
>  	user_enter();
>  }
>  
> +/*
> + * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
> + * changes likely come with new fields that should be added below.
> + */
> +static_assert(NSIGILL	== 11);
> +static_assert(NSIGFPE	== 15);
> +static_assert(NSIGSEGV	== 9);
> +static_assert(NSIGBUS	== 5);
> +static_assert(NSIGTRAP	== 6);
> +static_assert(NSIGCHLD	== 6);
> +static_assert(NSIGSYS	== 2);
> +static_assert(offsetof(siginfo_t, si_signo)	== 0x00);
> +static_assert(offsetof(siginfo_t, si_errno)	== 0x04);
> +static_assert(offsetof(siginfo_t, si_code)	== 0x08);
> +static_assert(offsetof(siginfo_t, si_pid)	== 0x10);
> +static_assert(offsetof(siginfo_t, si_uid)	== 0x14);
> +static_assert(offsetof(siginfo_t, si_tid)	== 0x10);
> +static_assert(offsetof(siginfo_t, si_overrun)	== 0x14);
> +static_assert(offsetof(siginfo_t, si_status)	== 0x18);
> +static_assert(offsetof(siginfo_t, si_utime)	== 0x20);
> +static_assert(offsetof(siginfo_t, si_stime)	== 0x28);
> +static_assert(offsetof(siginfo_t, si_value)	== 0x18);
> +static_assert(offsetof(siginfo_t, si_int)	== 0x18);
> +static_assert(offsetof(siginfo_t, si_ptr)	== 0x18);
> +static_assert(offsetof(siginfo_t, si_addr)	== 0x10);
> +static_assert(offsetof(siginfo_t, si_trapno)	== 0x18);
> +static_assert(offsetof(siginfo_t, si_addr_lsb)	== 0x20);
> +static_assert(offsetof(siginfo_t, si_lower)	== 0x28);
> +static_assert(offsetof(siginfo_t, si_upper)	== 0x30);
> +static_assert(offsetof(siginfo_t, si_pkey)	== 0x28);
> +static_assert(offsetof(siginfo_t, si_perf)	== 0x20);
> +static_assert(offsetof(siginfo_t, si_band)	== 0x10);
> +static_assert(offsetof(siginfo_t, si_fd)	== 0x14);
Marco Elver April 30, 2021, 6:11 p.m. UTC | #2
On Fri, 30 Apr 2021 at 19:42, Eric W. Biederman <ebiederm@xmission.com> wrote:
>
> Marco Elver <elver@google.com> writes:
>
> > To help catch ABI breaks at compile-time, add compile-time assertions to
> > verify the siginfo_t layout. Unlike other architectures, sparc64 is
> > special, because it is one of few architectures requiring si_trapno.
> > ABI breaks around that field would only be caught here.
>
> Arnd Bergman recently pointed out that we can move si_trapno into the
> union and make it specific to a handful of signals.  Like we do other
> items in the union.
>
> Given that the code of perf_sigtrap is pretty much broken if si_trapno
> needs to be filled out.  I think we should make that change before
> we set this ABI in stone like this.
>
> Otherwise this looks good.

Thanks, that's reasonable -- I'll reply to the other thread in a few minutes.

-- Marco

> Eric
>
> > Link: https://lkml.kernel.org/r/m11rat9f85.fsf@fess.ebiederm.org
> > Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
> > Signed-off-by: Marco Elver <elver@google.com>
> > ---
> >  arch/sparc/kernel/signal32.c  | 34 ++++++++++++++++++++++++++++++++++
> >  arch/sparc/kernel/signal_64.c | 33 +++++++++++++++++++++++++++++++++
> >  2 files changed, 67 insertions(+)
> >
> > diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
> > index e9695a06492f..778ed5c26d4a 100644
> > --- a/arch/sparc/kernel/signal32.c
> > +++ b/arch/sparc/kernel/signal32.c
> > @@ -745,3 +745,37 @@ asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
> >  out:
> >       return ret;
> >  }
> > +
> > +/*
> > + * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
> > + * changes likely come with new fields that should be added below.
> > + */
> > +static_assert(NSIGILL        == 11);
> > +static_assert(NSIGFPE        == 15);
> > +static_assert(NSIGSEGV       == 9);
> > +static_assert(NSIGBUS        == 5);
> > +static_assert(NSIGTRAP       == 6);
> > +static_assert(NSIGCHLD       == 6);
> > +static_assert(NSIGSYS        == 2);
> > +static_assert(offsetof(compat_siginfo_t, si_signo)   == 0x00);
> > +static_assert(offsetof(compat_siginfo_t, si_errno)   == 0x04);
> > +static_assert(offsetof(compat_siginfo_t, si_code)    == 0x08);
> > +static_assert(offsetof(compat_siginfo_t, si_pid)     == 0x0c);
> > +static_assert(offsetof(compat_siginfo_t, si_uid)     == 0x10);
> > +static_assert(offsetof(compat_siginfo_t, si_tid)     == 0x0c);
> > +static_assert(offsetof(compat_siginfo_t, si_overrun) == 0x10);
> > +static_assert(offsetof(compat_siginfo_t, si_status)  == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_utime)   == 0x18);
> > +static_assert(offsetof(compat_siginfo_t, si_stime)   == 0x1c);
> > +static_assert(offsetof(compat_siginfo_t, si_value)   == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_int)     == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_ptr)     == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_addr)    == 0x0c);
> > +static_assert(offsetof(compat_siginfo_t, si_trapno)  == 0x10);
> > +static_assert(offsetof(compat_siginfo_t, si_addr_lsb)        == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_lower)   == 0x18);
> > +static_assert(offsetof(compat_siginfo_t, si_upper)   == 0x1c);
> > +static_assert(offsetof(compat_siginfo_t, si_pkey)    == 0x18);
> > +static_assert(offsetof(compat_siginfo_t, si_perf)    == 0x14);
> > +static_assert(offsetof(compat_siginfo_t, si_band)    == 0x0c);
> > +static_assert(offsetof(compat_siginfo_t, si_fd)              == 0x10);
> > diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c
> > index a0eec62c825d..c9bbf5f29078 100644
> > --- a/arch/sparc/kernel/signal_64.c
> > +++ b/arch/sparc/kernel/signal_64.c
> > @@ -556,3 +556,36 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long
> >       user_enter();
> >  }
> >
> > +/*
> > + * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
> > + * changes likely come with new fields that should be added below.
> > + */
> > +static_assert(NSIGILL        == 11);
> > +static_assert(NSIGFPE        == 15);
> > +static_assert(NSIGSEGV       == 9);
> > +static_assert(NSIGBUS        == 5);
> > +static_assert(NSIGTRAP       == 6);
> > +static_assert(NSIGCHLD       == 6);
> > +static_assert(NSIGSYS        == 2);
> > +static_assert(offsetof(siginfo_t, si_signo)  == 0x00);
> > +static_assert(offsetof(siginfo_t, si_errno)  == 0x04);
> > +static_assert(offsetof(siginfo_t, si_code)   == 0x08);
> > +static_assert(offsetof(siginfo_t, si_pid)    == 0x10);
> > +static_assert(offsetof(siginfo_t, si_uid)    == 0x14);
> > +static_assert(offsetof(siginfo_t, si_tid)    == 0x10);
> > +static_assert(offsetof(siginfo_t, si_overrun)        == 0x14);
> > +static_assert(offsetof(siginfo_t, si_status) == 0x18);
> > +static_assert(offsetof(siginfo_t, si_utime)  == 0x20);
> > +static_assert(offsetof(siginfo_t, si_stime)  == 0x28);
> > +static_assert(offsetof(siginfo_t, si_value)  == 0x18);
> > +static_assert(offsetof(siginfo_t, si_int)    == 0x18);
> > +static_assert(offsetof(siginfo_t, si_ptr)    == 0x18);
> > +static_assert(offsetof(siginfo_t, si_addr)   == 0x10);
> > +static_assert(offsetof(siginfo_t, si_trapno) == 0x18);
> > +static_assert(offsetof(siginfo_t, si_addr_lsb)       == 0x20);
> > +static_assert(offsetof(siginfo_t, si_lower)  == 0x28);
> > +static_assert(offsetof(siginfo_t, si_upper)  == 0x30);
> > +static_assert(offsetof(siginfo_t, si_pkey)   == 0x28);
> > +static_assert(offsetof(siginfo_t, si_perf)   == 0x20);
> > +static_assert(offsetof(siginfo_t, si_band)   == 0x10);
> > +static_assert(offsetof(siginfo_t, si_fd)     == 0x14);
David Miller April 30, 2021, 10:22 p.m. UTC | #3
From: Marco Elver <elver@google.com>
Date: Thu, 29 Apr 2021 21:07:32 +0200

> To help catch ABI breaks at compile-time, add compile-time assertions to
> verify the siginfo_t layout. Unlike other architectures, sparc64 is
> special, because it is one of few architectures requiring si_trapno.
> ABI breaks around that field would only be caught here.
> 
> Link: https://lkml.kernel.org/r/m11rat9f85.fsf@fess.ebiederm.org
> Suggested-by: Eric W. Biederman <ebiederm@xmission.com>
> Signed-off-by: Marco Elver <elver@google.com>

Acked-by: David S. Miller <davem@davemloft.net>
diff mbox series

Patch

diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
index e9695a06492f..778ed5c26d4a 100644
--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -745,3 +745,37 @@  asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
 out:
 	return ret;
 }
+
+/*
+ * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
+ * changes likely come with new fields that should be added below.
+ */
+static_assert(NSIGILL	== 11);
+static_assert(NSIGFPE	== 15);
+static_assert(NSIGSEGV	== 9);
+static_assert(NSIGBUS	== 5);
+static_assert(NSIGTRAP	== 6);
+static_assert(NSIGCHLD	== 6);
+static_assert(NSIGSYS	== 2);
+static_assert(offsetof(compat_siginfo_t, si_signo)	== 0x00);
+static_assert(offsetof(compat_siginfo_t, si_errno)	== 0x04);
+static_assert(offsetof(compat_siginfo_t, si_code)	== 0x08);
+static_assert(offsetof(compat_siginfo_t, si_pid)	== 0x0c);
+static_assert(offsetof(compat_siginfo_t, si_uid)	== 0x10);
+static_assert(offsetof(compat_siginfo_t, si_tid)	== 0x0c);
+static_assert(offsetof(compat_siginfo_t, si_overrun)	== 0x10);
+static_assert(offsetof(compat_siginfo_t, si_status)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_utime)	== 0x18);
+static_assert(offsetof(compat_siginfo_t, si_stime)	== 0x1c);
+static_assert(offsetof(compat_siginfo_t, si_value)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_int)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_ptr)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_addr)	== 0x0c);
+static_assert(offsetof(compat_siginfo_t, si_trapno)	== 0x10);
+static_assert(offsetof(compat_siginfo_t, si_addr_lsb)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_lower)	== 0x18);
+static_assert(offsetof(compat_siginfo_t, si_upper)	== 0x1c);
+static_assert(offsetof(compat_siginfo_t, si_pkey)	== 0x18);
+static_assert(offsetof(compat_siginfo_t, si_perf)	== 0x14);
+static_assert(offsetof(compat_siginfo_t, si_band)	== 0x0c);
+static_assert(offsetof(compat_siginfo_t, si_fd)		== 0x10);
diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c
index a0eec62c825d..c9bbf5f29078 100644
--- a/arch/sparc/kernel/signal_64.c
+++ b/arch/sparc/kernel/signal_64.c
@@ -556,3 +556,36 @@  void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long
 	user_enter();
 }
 
+/*
+ * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
+ * changes likely come with new fields that should be added below.
+ */
+static_assert(NSIGILL	== 11);
+static_assert(NSIGFPE	== 15);
+static_assert(NSIGSEGV	== 9);
+static_assert(NSIGBUS	== 5);
+static_assert(NSIGTRAP	== 6);
+static_assert(NSIGCHLD	== 6);
+static_assert(NSIGSYS	== 2);
+static_assert(offsetof(siginfo_t, si_signo)	== 0x00);
+static_assert(offsetof(siginfo_t, si_errno)	== 0x04);
+static_assert(offsetof(siginfo_t, si_code)	== 0x08);
+static_assert(offsetof(siginfo_t, si_pid)	== 0x10);
+static_assert(offsetof(siginfo_t, si_uid)	== 0x14);
+static_assert(offsetof(siginfo_t, si_tid)	== 0x10);
+static_assert(offsetof(siginfo_t, si_overrun)	== 0x14);
+static_assert(offsetof(siginfo_t, si_status)	== 0x18);
+static_assert(offsetof(siginfo_t, si_utime)	== 0x20);
+static_assert(offsetof(siginfo_t, si_stime)	== 0x28);
+static_assert(offsetof(siginfo_t, si_value)	== 0x18);
+static_assert(offsetof(siginfo_t, si_int)	== 0x18);
+static_assert(offsetof(siginfo_t, si_ptr)	== 0x18);
+static_assert(offsetof(siginfo_t, si_addr)	== 0x10);
+static_assert(offsetof(siginfo_t, si_trapno)	== 0x18);
+static_assert(offsetof(siginfo_t, si_addr_lsb)	== 0x20);
+static_assert(offsetof(siginfo_t, si_lower)	== 0x28);
+static_assert(offsetof(siginfo_t, si_upper)	== 0x30);
+static_assert(offsetof(siginfo_t, si_pkey)	== 0x28);
+static_assert(offsetof(siginfo_t, si_perf)	== 0x20);
+static_assert(offsetof(siginfo_t, si_band)	== 0x10);
+static_assert(offsetof(siginfo_t, si_fd)	== 0x14);