All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/compat.c: mark expected switch fall-throughs
@ 2019-04-16  7:29 Stephen Rothwell
  2019-04-16  8:32 ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Rothwell @ 2019-04-16  7:29 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: Arnd Bergmann, Deepa Dinamani, Gustavo A. R. Silva, Kees Cook, Jann Horn

[-- Attachment #1: Type: text/plain, Size: 1601 bytes --]

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

This patch aims to suppress up to 3 missing-break-in-switch false
positives on some architectures.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 kernel/compat.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

I know that this makes the lines longer than 80 characters, but I
though that this was better than adding new lines.

Build tested on PowerPC.

diff --git a/kernel/compat.c b/kernel/compat.c
index d8a36c6ad7c9..b61f75df188d 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -345,9 +345,9 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
 	if (copy_from_user(&v, compat, sizeof(compat_sigset_t)))
 		return -EFAULT;
 	switch (_NSIG_WORDS) {
-	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 );
-	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 );
-	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 );
+	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 ); /* fall through */
+	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 ); /* fall through */
+	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 ); /* fall through */
 	case 1: set->sig[0] = v.sig[0] | (((long)v.sig[1]) << 32 );
 	}
 #else
-- 
2.20.1

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kernel/compat.c: mark expected switch fall-throughs
  2019-04-16  7:29 [PATCH] kernel/compat.c: mark expected switch fall-throughs Stephen Rothwell
@ 2019-04-16  8:32 ` Arnd Bergmann
  2019-04-16  8:53   ` Stephen Rothwell
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2019-04-16  8:32 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Linux Kernel Mailing List, Deepa Dinamani, Gustavo A. R. Silva,
	Kees Cook, Jann Horn

On Tue, Apr 16, 2019 at 9:29 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> In preparation to enabling -Wimplicit-fallthrough, mark switch cases
> where we are expecting to fall through.
>
> This patch aims to suppress up to 3 missing-break-in-switch false
> positives on some architectures.
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Deepa Dinamani <deepa.kernel@gmail.com>
> Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Jann Horn <jannh@google.com>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>

Acked-by: Arnd Bergmann <arnd@arndb.de>

> ---
>  kernel/compat.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> I know that this makes the lines longer than 80 characters, but I
> though that this was better than adding new lines.

It's a bit inconsistent though since put_compat_sigset() has the
comments in separate lines, as of commit 89976005536c
("include/linux/compat.h: mark expected switch fall-throughs").

I don't care either way, but it might be better to do it the same way
for both.

We could also consider just getting rid of put_compat_sigset() and
get_compat_sigset() but replacing them with a combined
put_sigset()/get_sigset() that does the right thing for both native
and compat tasks. This lets us kill a couple of compat system
calls that only differ in their sigset_t argument. On little-endian
systems (which are the vast majority of the installed base), there
is no difference anyway there is no overhead anyway since
native and compat sigset_t are identical.

        Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kernel/compat.c: mark expected switch fall-throughs
  2019-04-16  8:32 ` Arnd Bergmann
@ 2019-04-16  8:53   ` Stephen Rothwell
  2019-04-16  9:14     ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Rothwell @ 2019-04-16  8:53 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Linux Kernel Mailing List, Deepa Dinamani, Gustavo A. R. Silva,
	Kees Cook, Jann Horn

[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]

Hi Arnd,

On Tue, 16 Apr 2019 10:32:55 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>

Thanks

> It's a bit inconsistent though since put_compat_sigset() has the
> comments in separate lines, as of commit 89976005536c
> ("include/linux/compat.h: mark expected switch fall-throughs").

OK, I wasn't aware of that one.

> I don't care either way, but it might be better to do it the same way
> for both.

Indeed, I will redo it that way (with your Acked-by).

> We could also consider just getting rid of put_compat_sigset() and
> get_compat_sigset() but replacing them with a combined
> put_sigset()/get_sigset() that does the right thing for both native
> and compat tasks. This lets us kill a couple of compat system
> calls that only differ in their sigset_t argument. On little-endian
> systems (which are the vast majority of the installed base), there
> is no difference anyway there is no overhead anyway since
> native and compat sigset_t are identical.

That sounds like a bigger patch that would require some real testing :-)

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kernel/compat.c: mark expected switch fall-throughs
  2019-04-16  8:53   ` Stephen Rothwell
@ 2019-04-16  9:14     ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2019-04-16  9:14 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Linux Kernel Mailing List, Deepa Dinamani, Gustavo A. R. Silva,
	Kees Cook, Jann Horn

On Tue, Apr 16, 2019 at 10:54 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> On Tue, 16 Apr 2019 10:32:55 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
> > We could also consider just getting rid of put_compat_sigset() and
> > get_compat_sigset() but replacing them with a combined
> > put_sigset()/get_sigset() that does the right thing for both native
> > and compat tasks. This lets us kill a couple of compat system
> > calls that only differ in their sigset_t argument. On little-endian
> > systems (which are the vast majority of the installed base), there
> > is no difference anyway there is no overhead anyway since
> > native and compat sigset_t are identical.
>
> That sounds like a bigger patch that would require some real testing :-)

Yes, definitely. I mainly mentioned it in case someone wants to
do that work anyway, as it would avoid the need for your patch.

      Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] kernel/compat.c: mark expected switch fall-throughs
@ 2019-05-15  5:23 Stephen Rothwell
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Rothwell @ 2019-05-15  5:23 UTC (permalink / raw)
  To: Linus
  Cc: Arnd Bergmann, Deepa Dinamani, Gustavo A. R. Silva, Kees Cook,
	Jann Horn, Linux-kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

This patch aims to suppress 3 missing-break-in-switch false positives
on some architectures.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 kernel/compat.c | 3 +++
 1 file changed, 3 insertions(+)

Hi Linus,

This has been sitting in my fixes tree in linux-next for quite some
time.  It silences some warnings that irritated me in my builds since I
am building with -Wimplicit-fallthrough to help Gustavo catch new
additions.

diff --git a/kernel/compat.c b/kernel/compat.c
index d8a36c6ad7c9..b5f7063c0db6 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -346,8 +346,11 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
 		return -EFAULT;
 	switch (_NSIG_WORDS) {
 	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 );
+		/* fall through */
 	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 );
+		/* fall through */
 	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 );
+		/* fall through */
 	case 1: set->sig[0] = v.sig[0] | (((long)v.sig[1]) << 32 );
 	}
 #else
-- 
2.20.1

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-15  5:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16  7:29 [PATCH] kernel/compat.c: mark expected switch fall-throughs Stephen Rothwell
2019-04-16  8:32 ` Arnd Bergmann
2019-04-16  8:53   ` Stephen Rothwell
2019-04-16  9:14     ` Arnd Bergmann
2019-05-15  5:23 Stephen Rothwell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.