From: Marco Elver <elver@google.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>,
Peter Collingbourne <pcc@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Florian Weimer <fweimer@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Dmitry Vyukov <dvyukov@google.com>,
Alexander Potapenko <glider@google.com>,
sparclinux <sparclinux@vger.kernel.org>,
linux-arch <linux-arch@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux API <linux-api@vger.kernel.org>,
kasan-dev <kasan-dev@googlegroups.com>
Subject: Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Date: Tue, 4 May 2021 11:52:54 +0200 [thread overview]
Message-ID: <YJEZdhe6JGFNYlum@elver.google.com> (raw)
In-Reply-To: <CAMn1gO7+wMzHoGtp2t3=jJxRmPAGEbhnUDFLQQ0vFXZ2NP8stg@mail.gmail.com>
On Mon, May 03, 2021 at 09:03PM -0700, Peter Collingbourne wrote:
> On Mon, May 3, 2021 at 8:42 PM Eric W. Biederman <ebiederm@xmission.com> wrote:
> > Marco Elver <elver@google.com> writes:
> > > On Mon, 3 May 2021 at 23:04, Eric W. Biederman <ebiederm@xmission.com> wrote:
> > >> "Eric W. Beiderman" <ebiederm@xmission.com> writes:
> > >> > From: "Eric W. Biederman" <ebiederm@xmission.com>
> > >> >
> > >> > The si_perf code really wants to add a u64 field. This change enables
> > >> > that by reorganizing the definition of siginfo_t, so that a 64bit
> > >> > field can be added without increasing the alignment of other fields.
> > >
> > > If you can, it'd be good to have an explanation for this, because it's
> > > not at all obvious -- some future archeologist will wonder how we ever
> > > came up with this definition of siginfo...
> > >
> > > (I see the trick here is that before the union would have changed
> > > alignment, introducing padding after the 3 ints -- but now because the
> > > 3 ints are inside the union the union's padding no longer adds padding
> > > for these ints. Perhaps you can explain it better than I can. Also
> > > see below.)
> >
> > Yes. The big idea is adding a 64bit field into the second union
> > in the _sigfault case will increase the alignment of that second
> > union to 64bit.
> >
> > In the 64bit case the alignment is already 64bit so it is not an
> > issue.
> >
> > In the 32bit case there are 3 ints followed by a pointer. When the
> > 64bit member is added the alignment of _segfault becomes 64bit. That
> > 64bit alignment after 3 ints changes the location of the 32bit pointer.
> >
> > By moving the 3 preceding ints into _segfault that does not happen.
> >
> >
> >
> > There remains one very subtle issue that I think isn't a problem
> > but I would appreciate someone else double checking me.
> >
> >
> > The old definition of siginfo_t on 32bit almost certainly had 32bit
> > alignment. With the addition of a 64bit member siginfo_t gains 64bit
> > alignment. This difference only matters if the 64bit field is accessed.
> > Accessing a 64bit field with 32bit alignment will cause unaligned access
> > exceptions on some (most?) architectures.
> >
> > For the 64bit field to be accessed the code needs to be recompiled with
> > the new headers. Which implies that when everything is recompiled
> > siginfo_t will become 64bit aligned.
> >
> >
> > So the change should be safe unless someone is casting something with
> > 32bit alignment into siginfo_t.
>
> How about if someone has a field of type siginfo_t as an element of a
> struct? For example:
>
> struct foo {
> int x;
> siginfo_t y;
> };
>
> With this change wouldn't the y field move from offset 4 to offset 8?
This is a problem if such a struct is part of the ABI -- in the kernel I
found these that might be problematic:
| arch/csky/kernel/signal.c:struct rt_sigframe {
| arch/csky/kernel/signal.c- /*
| arch/csky/kernel/signal.c- * pad[3] is compatible with the same struct defined in
| arch/csky/kernel/signal.c- * gcc/libgcc/config/csky/linux-unwind.h
| arch/csky/kernel/signal.c- */
| arch/csky/kernel/signal.c- int pad[3];
| arch/csky/kernel/signal.c- struct siginfo info;
| arch/csky/kernel/signal.c- struct ucontext uc;
| arch/csky/kernel/signal.c-};
| [...]
| arch/parisc/include/asm/rt_sigframe.h-#define SIGRETURN_TRAMP 4
| arch/parisc/include/asm/rt_sigframe.h-#define SIGRESTARTBLOCK_TRAMP 5
| arch/parisc/include/asm/rt_sigframe.h-#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)
| arch/parisc/include/asm/rt_sigframe.h-
| arch/parisc/include/asm/rt_sigframe.h:struct rt_sigframe {
| arch/parisc/include/asm/rt_sigframe.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c
| arch/parisc/include/asm/rt_sigframe.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK
| arch/parisc/include/asm/rt_sigframe.h- trampoline we left on the stack (we were bad and didn't
| arch/parisc/include/asm/rt_sigframe.h- change sp so we could run really fast.) */
| arch/parisc/include/asm/rt_sigframe.h- unsigned int tramp[TRAMP_SIZE];
| arch/parisc/include/asm/rt_sigframe.h- struct siginfo info;
| [..]
| arch/parisc/kernel/signal32.h-#define COMPAT_SIGRETURN_TRAMP 4
| arch/parisc/kernel/signal32.h-#define COMPAT_SIGRESTARTBLOCK_TRAMP 5
| arch/parisc/kernel/signal32.h-#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \
| arch/parisc/kernel/signal32.h- COMPAT_SIGRESTARTBLOCK_TRAMP)
| arch/parisc/kernel/signal32.h-
| arch/parisc/kernel/signal32.h:struct compat_rt_sigframe {
| arch/parisc/kernel/signal32.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c
| arch/parisc/kernel/signal32.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK
| arch/parisc/kernel/signal32.h- trampoline we left on the stack (we were bad and didn't
| arch/parisc/kernel/signal32.h- change sp so we could run really fast.) */
| arch/parisc/kernel/signal32.h- compat_uint_t tramp[COMPAT_TRAMP_SIZE];
| arch/parisc/kernel/signal32.h- compat_siginfo_t info;
Adding these static asserts to parisc shows the problem:
| diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c
| index fb1e94a3982b..0be582fb81be 100644
| --- a/arch/parisc/kernel/signal.c
| +++ b/arch/parisc/kernel/signal.c
| @@ -610,3 +610,6 @@ void do_notify_resume(struct pt_regs *regs, long in_syscall)
| if (test_thread_flag(TIF_NOTIFY_RESUME))
| tracehook_notify_resume(regs);
| }
| +
| +static_assert(sizeof(unsigned long) == 4); // 32 bit build
| +static_assert(offsetof(struct rt_sigframe, info) == 9 * 4);
This passes without the siginfo rework in this patch. With it:
| ./include/linux/build_bug.h:78:41: error: static assertion failed: "offsetof(struct rt_sigframe, info) == 9 * 4"
As sad as it is, I don't think we can have our cake and eat it, too. :-(
Unless you see why this is fine, I think we need to drop this patch and
go back to the simpler version you had.
Thanks,
-- Marco
next prev parent reply other threads:[~2021-05-04 9:53 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 7:48 siginfo_t ABI break on sparc64 from si_addr_lsb move 3y ago Marco Elver
2021-04-29 17:23 ` Eric W. Biederman
2021-04-29 18:46 ` Marco Elver
2021-04-29 20:48 ` Arnd Bergmann
2021-04-30 17:08 ` Eric W. Biederman
2021-04-30 19:07 ` Marco Elver
2021-04-30 20:15 ` Eric W. Biederman
2021-04-30 23:50 ` Marco Elver
2021-04-30 22:49 ` [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union Eric W. Biederman
2021-04-30 22:50 ` [PATCH 1/3] siginfo: Move si_trapno inside the union inside _si_fault Eric W. Biederman
2021-05-01 10:31 ` Marco Elver
2021-05-02 18:27 ` Eric W. Biederman
2021-04-30 22:54 ` [PATCH 2/3] signal: Implement SIL_FAULT_TRAPNO Eric W. Biederman
2021-04-30 23:19 ` Eric W. Biederman
2021-05-01 10:33 ` Marco Elver
2021-05-02 18:24 ` Eric W. Biederman
2021-04-30 22:55 ` [PATCH 3/3] signal: Use dedicated helpers to send signals with si_trapno set Eric W. Biederman
2021-05-01 10:33 ` Marco Elver
2021-04-30 22:56 ` [PATCH 4/3] signal: Remove __ARCH_SI_TRAPNO Eric W. Biederman
2021-04-30 23:23 ` Is perf_sigtrap synchronous? Eric W. Biederman
2021-05-01 0:28 ` Marco Elver
2021-04-30 23:42 ` [PATCH 5/3] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency Eric W. Biederman
2021-05-01 10:35 ` Marco Elver
2021-04-30 23:43 ` [PATCH 6/3] signal: Factor force_sig_perf out of perf_sigtrap Eric W. Biederman
2021-05-01 10:45 ` Marco Elver
2021-04-30 23:43 ` [PATCH 7/3] signal: Deliver all of the perf_data in si_perf Eric W. Biederman
2021-05-01 10:47 ` Marco Elver
2021-05-02 18:39 ` Eric W. Biederman
2021-05-02 19:13 ` Marco Elver
2021-05-03 12:44 ` Peter Zijlstra
2021-05-03 19:38 ` Eric W. Biederman
2021-05-03 19:53 ` Marco Elver
2021-04-30 23:47 ` [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union Eric W. Biederman
2021-05-01 0:37 ` Marco Elver
2021-05-01 15:16 ` Eric W. Biederman
2021-05-01 16:24 ` Marco Elver
2021-05-03 20:25 ` [PATCH 00/12] signal: sort out si_trapno and si_perf Eric W. Biederman
2021-05-03 20:38 ` [PATCH 01/12] sparc64: Add compile-time asserts for siginfo_t offsets Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 02/12] arm: " Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 03/12] arm64: " Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 04/12] siginfo: Move si_trapno inside the union inside _si_fault Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 05/12] signal: Implement SIL_FAULT_TRAPNO Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 06/12] signal: Use dedicated helpers to send signals with si_trapno set Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 07/12] signal: Remove __ARCH_SI_TRAPNO Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 08/12] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 09/12] signal: Factor force_sig_perf out of perf_sigtrap Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible Eric W. Beiderman
2021-05-03 21:04 ` Eric W. Biederman
2021-05-03 22:47 ` Marco Elver
2021-05-04 3:42 ` Eric W. Biederman
2021-05-04 4:03 ` Peter Collingbourne
2021-05-04 9:52 ` Marco Elver [this message]
2021-05-04 16:16 ` Eric W. Biederman
2021-05-03 20:38 ` [PATCH 11/12] signal: Deliver all of the siginfo perf data in _perf Eric W. Beiderman
2021-05-03 20:38 ` [PATCH 12/12] signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo Eric W. Beiderman
2021-05-04 21:13 ` [PATCH v3 00/12] signal: sort out si_trapno and si_perf Eric W. Biederman
2021-05-04 22:05 ` Marco Elver
2021-05-05 14:12 ` Eric W. Biederman
2021-05-05 14:10 ` [PATCH v3 01/12] sparc64: Add compile-time asserts for siginfo_t offsets Eric W. Beiderman
2021-05-05 14:10 ` [PATCH v3 02/12] arm: " Eric W. Beiderman
2021-05-05 14:10 ` [PATCH v3 03/12] arm64: " Eric W. Beiderman
2021-05-05 14:10 ` [PATCH v3 04/12] signal: Verify the alignment and size of siginfo_t Eric W. Beiderman
2021-05-05 17:24 ` Marco Elver
2021-05-05 14:10 ` [PATCH v3 05/12] siginfo: Move si_trapno inside the union inside _si_fault Eric W. Beiderman
2021-05-05 14:10 ` [PATCH v3 06/12] signal: Implement SIL_FAULT_TRAPNO Eric W. Beiderman
2021-05-05 17:25 ` Marco Elver
2021-05-05 14:10 ` [PATCH v3 07/12] signal: Use dedicated helpers to send signals with si_trapno set Eric W. Beiderman
2021-05-05 17:25 ` Marco Elver
2021-05-05 14:10 ` [PATCH v3 08/12] signal: Remove __ARCH_SI_TRAPNO Eric W. Beiderman
2021-05-05 17:25 ` Marco Elver
2021-05-05 14:10 ` [PATCH v3 09/12] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency Eric W. Beiderman
2021-05-05 17:26 ` Marco Elver
2021-05-05 14:10 ` [PATCH v3 10/12] signal: Factor force_sig_perf out of perf_sigtrap Eric W. Beiderman
2021-05-05 17:26 ` Marco Elver
2021-05-06 10:54 ` Peter Zijlstra
2021-05-05 14:11 ` [PATCH v3 11/12] signal: Deliver all of the siginfo perf data in _perf Eric W. Beiderman
2021-05-05 17:27 ` Marco Elver
2021-05-05 14:11 ` [PATCH v3 12/12] signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo Eric W. Beiderman
2021-05-05 17:27 ` Marco Elver
2021-05-05 17:28 ` [PATCH v3 00/12] signal: sort out si_trapno and si_perf Marco Elver
2021-05-06 7:00 ` Geert Uytterhoeven
2021-05-06 10:43 ` Marco Elver
2021-05-06 15:28 ` Eric W. Biederman
2021-05-06 15:14 ` Eric W. Biederman
2021-05-14 4:54 ` [GIT PULL] siginfo: ABI fixes for v5.13-rc2 Eric W. Biederman
2021-05-14 19:14 ` Linus Torvalds
2021-05-14 21:15 ` Eric W. Biederman
2021-05-14 22:38 ` Eric W. Biederman
2021-05-16 7:40 ` Ingo Molnar
2021-05-17 15:29 ` Eric W. Biederman
2021-05-21 14:59 ` [GIT PULL] siginfo: ABI fixes for v5.13-rc3 Eric W. Biederman
2021-05-21 16:34 ` pr-tracker-bot
2021-05-17 19:56 ` [PATCH v4 0/5] siginfo: ABI fixes for TRAP_PERF Eric W. Biederman
2021-05-17 19:57 ` [PATCH v4 1/5] siginfo: Move si_trapno inside the union inside _si_fault Eric W. Beiderman
2021-05-17 19:57 ` [PATCH v4 2/5] signal: Implement SIL_FAULT_TRAPNO Eric W. Beiderman
2021-05-17 19:57 ` [PATCH v4 3/5] signal: Factor force_sig_perf out of perf_sigtrap Eric W. Beiderman
2021-05-17 19:57 ` [PATCH v4 4/5] signal: Deliver all of the siginfo perf data in _perf Eric W. Beiderman
2021-05-17 19:57 ` [PATCH v4 5/5] signalfd: Remove SIL_PERF_EVENT fields from signalfd_siginfo Eric W. Beiderman
2021-05-17 20:53 ` [PATCH v4 0/5] siginfo: ABI fixes for TRAP_PERF Marco Elver
2021-05-18 3:46 ` Eric W. Biederman
2021-05-18 6:44 ` Marco Elver
2021-05-01 16:26 ` [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union Marco Elver
2021-07-15 18:09 ` [PATCH 0/6] Final si_trapno bits Eric W. Biederman
2021-07-15 18:11 ` [PATCH 1/6] sparc64: Add compile-time asserts for siginfo_t offsets Eric W. Biederman
2021-07-15 18:11 ` [PATCH 2/6] arm: " Eric W. Biederman
2021-07-15 18:11 ` [PATCH 3/6] arm64: " Eric W. Biederman
2021-07-15 18:12 ` [PATCH 4/6] signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP Eric W. Biederman
2021-07-16 11:49 ` Marco Elver
2021-07-15 18:12 ` [PATCH 5/6] signal/alpha: si_trapno is only used with SIGFPE and SIGTRAP TRAP_UNK Eric W. Biederman
2021-07-16 11:48 ` Marco Elver
2021-07-15 18:13 ` [PATCH 6/6] signal: Remove the generic __ARCH_SI_TRAPNO support Eric W. Biederman
2021-07-16 11:48 ` Marco Elver
2021-07-16 11:50 ` [PATCH 0/6] Final si_trapno bits Marco Elver
2021-07-16 16:08 ` Eric W. Biederman
2021-07-16 17:15 ` Marco Elver
2021-07-16 16:06 ` [PATCH 7/7] signal: Verify the alignment and size of siginfo_t Eric W. Biederman
2021-07-16 16:07 ` [PATCH 8/6] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency Eric W. Biederman
2021-04-30 20:43 ` siginfo_t ABI break on sparc64 from si_addr_lsb move 3y ago Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YJEZdhe6JGFNYlum@elver.google.com \
--to=elver@google.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dvyukov@google.com \
--cc=ebiederm@xmission.com \
--cc=fweimer@redhat.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=pcc@google.com \
--cc=peterz@infradead.org \
--cc=sparclinux@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).