LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] ppdev: Distribute switch variables for initialization
@ 2020-02-20  6:23 Kees Cook
  2020-02-24 12:34 ` Sudip Mukherjee
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2020-02-20  6:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Sudip Mukherjee, Sudip Mukherjee
  Cc: Alexander Potapenko, Kees Cook, linux-kernel

Variables declared in a switch statement before any case statements
cannot be automatically initialized with compiler instrumentation (as
they are not part of any execution flow). With GCC's proposed automatic
stack variable initialization feature, this triggers a warning (and they
don't get initialized). Clang's automatic stack variable initialization
(via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also
doesn't initialize such variables[1]. Note that these warnings (or silent
skipping) happen before the dead-store elimination optimization phase,
so even when the automatic initializations are later elided in favor of
direct initializations, the warnings remain.

To avoid these problems, move such variables into the "case" where
they're used or lift them up into the main function body.

drivers/char/ppdev.c: In function ‘pp_do_ioctl’:
drivers/char/ppdev.c:516:25: warning: statement will never be executed [-Wswitch-unreachable]
  516 |   struct ieee1284_info *info;
      |                         ^~~~

[1] https://bugs.llvm.org/show_bug.cgi?id=44916

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/char/ppdev.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 2c2381a806ae..38b46c7d1737 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -355,14 +355,19 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	struct pp_struct *pp = file->private_data;
 	struct parport *port;
 	void __user *argp = (void __user *)arg;
+	struct ieee1284_info *info;
+	unsigned char reg;
+	unsigned char mask;
+	int mode;
+	s32 time32[2];
+	s64 time64[2];
+	struct timespec64 ts;
+	int ret;
 
 	/* First handle the cases that don't take arguments. */
 	switch (cmd) {
 	case PPCLAIM:
 	    {
-		struct ieee1284_info *info;
-		int ret;
-
 		if (pp->flags & PP_CLAIMED) {
 			dev_dbg(&pp->pdev->dev, "you've already got it!\n");
 			return -EINVAL;
@@ -513,15 +518,6 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 	port = pp->pdev->port;
 	switch (cmd) {
-		struct ieee1284_info *info;
-		unsigned char reg;
-		unsigned char mask;
-		int mode;
-		s32 time32[2];
-		s64 time64[2];
-		struct timespec64 ts;
-		int ret;
-
 	case PPRSTATUS:
 		reg = parport_read_status(port);
 		if (copy_to_user(argp, &reg, sizeof(reg)))


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

* Re: [PATCH] ppdev: Distribute switch variables for initialization
  2020-02-20  6:23 [PATCH] ppdev: Distribute switch variables for initialization Kees Cook
@ 2020-02-24 12:34 ` Sudip Mukherjee
  2020-02-24 12:58   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Sudip Mukherjee @ 2020-02-24 12:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Alexander Potapenko, linux-kernel, Kees Cook

On Wed, Feb 19, 2020 at 10:23:11PM -0800, Kees Cook wrote:
> Variables declared in a switch statement before any case statements
> cannot be automatically initialized with compiler instrumentation (as
> they are not part of any execution flow). With GCC's proposed automatic
> stack variable initialization feature, this triggers a warning (and they
> don't get initialized). Clang's automatic stack variable initialization
> (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also
> doesn't initialize such variables[1]. Note that these warnings (or silent
> skipping) happen before the dead-store elimination optimization phase,
> so even when the automatic initializations are later elided in favor of
> direct initializations, the warnings remain.
> 
> To avoid these problems, move such variables into the "case" where
> they're used or lift them up into the main function body.
> 
> drivers/char/ppdev.c: In function ‘pp_do_ioctl’:
> drivers/char/ppdev.c:516:25: warning: statement will never be executed [-Wswitch-unreachable]
>   516 |   struct ieee1284_info *info;
>       |                         ^~~~
> 
> [1] https://bugs.llvm.org/show_bug.cgi?id=44916
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

Greg, Can you please take it in your tree...

--
Regards
Sudip

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

* Re: [PATCH] ppdev: Distribute switch variables for initialization
  2020-02-24 12:34 ` Sudip Mukherjee
@ 2020-02-24 12:58   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2020-02-24 12:58 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: Alexander Potapenko, linux-kernel, Kees Cook

On Mon, Feb 24, 2020 at 12:34:12PM +0000, Sudip Mukherjee wrote:
> On Wed, Feb 19, 2020 at 10:23:11PM -0800, Kees Cook wrote:
> > Variables declared in a switch statement before any case statements
> > cannot be automatically initialized with compiler instrumentation (as
> > they are not part of any execution flow). With GCC's proposed automatic
> > stack variable initialization feature, this triggers a warning (and they
> > don't get initialized). Clang's automatic stack variable initialization
> > (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also
> > doesn't initialize such variables[1]. Note that these warnings (or silent
> > skipping) happen before the dead-store elimination optimization phase,
> > so even when the automatic initializations are later elided in favor of
> > direct initializations, the warnings remain.
> > 
> > To avoid these problems, move such variables into the "case" where
> > they're used or lift them up into the main function body.
> > 
> > drivers/char/ppdev.c: In function ‘pp_do_ioctl’:
> > drivers/char/ppdev.c:516:25: warning: statement will never be executed [-Wswitch-unreachable]
> >   516 |   struct ieee1284_info *info;
> >       |                         ^~~~
> > 
> > [1] https://bugs.llvm.org/show_bug.cgi?id=44916
> > 
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Acked-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> 
> Greg, Can you please take it in your tree...

Already taken :)

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

end of thread, other threads:[~2020-02-24 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20  6:23 [PATCH] ppdev: Distribute switch variables for initialization Kees Cook
2020-02-24 12:34 ` Sudip Mukherjee
2020-02-24 12:58   ` Greg Kroah-Hartman

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).