Skip to content

Commit

Permalink
tty: Avoid the use of one-element arrays
Browse files Browse the repository at this point in the history
One-element arrays are being deprecated[1]. Replace the one-element arrays
with simple value types 'char reserved_char' and 'compat_int_t reserved'[2],
once it seems these are just placeholders for alignment.

Also, while there, use the preferred form for passing a size of a struct.
The alternative form where struct name is spelled out hurts readability
and introduces an opportunity for a bug when the variable type is changed
but the corresponding sizeof that is passed as argument is not.

Lastly, fix the checkpatch.pl warnings below:

ERROR: code indent should use tabs where possible
+        char    reserved_char;$

WARNING: please, no spaces at the start of a line
+        char    reserved_char;$

ERROR: code indent should use tabs where possible
+        compat_int_t    reserved;$

WARNING: please, no spaces at the start of a line
+        compat_int_t    reserved;$

[1] KSPP#79
[2] KSPP#86

Tested-by: kernel test robot <[email protected]>
Link: https://github.com/GustavoARSilva/linux-hardening/blob/master/cii/0-day/tty-20200716.md
Acked-by: Jiri Slaby <[email protected]>
Signed-off-by: Gustavo A. R. Silva <[email protected]>
  • Loading branch information
GustavoARSilva authored and intel-lab-lkp committed Jul 22, 2020
1 parent bd78ecd commit 7f3a4c0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions drivers/tty/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2673,25 +2673,25 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
#ifdef CONFIG_COMPAT

struct serial_struct32 {
compat_int_t type;
compat_int_t line;
compat_uint_t port;
compat_int_t irq;
compat_int_t flags;
compat_int_t xmit_fifo_size;
compat_int_t custom_divisor;
compat_int_t baud_base;
unsigned short close_delay;
char io_type;
char reserved_char[1];
compat_int_t hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
compat_uint_t iomem_base;
unsigned short iomem_reg_shift;
unsigned int port_high;
/* compat_ulong_t iomap_base FIXME */
compat_int_t reserved[1];
compat_int_t type;
compat_int_t line;
compat_uint_t port;
compat_int_t irq;
compat_int_t flags;
compat_int_t xmit_fifo_size;
compat_int_t custom_divisor;
compat_int_t baud_base;
unsigned short close_delay;
char io_type;
char reserved_char;
compat_int_t hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
compat_uint_t iomem_base;
unsigned short iomem_reg_shift;
unsigned int port_high;
/* compat_ulong_t iomap_base FIXME */
compat_int_t reserved;
};

static int compat_tty_tiocsserial(struct tty_struct *tty,
Expand All @@ -2705,7 +2705,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty,
struct serial_struct v;
int flags;

if (copy_from_user(&v32, ss, sizeof(struct serial_struct32)))
if (copy_from_user(&v32, ss, sizeof(*ss)))
return -EFAULT;

memcpy(&v, &v32, offsetof(struct serial_struct32, iomem_base));
Expand Down Expand Up @@ -2743,7 +2743,7 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
0xfffffff : ptr_to_compat(v.iomem_base);
v32.iomem_reg_shift = v.iomem_reg_shift;
v32.port_high = v.port_high;
if (copy_to_user(ss, &v32, sizeof(struct serial_struct32)))
if (copy_to_user(ss, &v32, sizeof(v32)))
err = -EFAULT;
}
return err;
Expand Down

0 comments on commit 7f3a4c0

Please sign in to comment.