linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] tty: Avoid the use of one-element arrays
@ 2020-07-16 18:08 Gustavo A. R. Silva
  2020-07-17  6:10 ` Jiri Slaby
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-16 18:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-kernel, Gustavo A. R. Silva

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] https://github.com/KSPP/linux/issues/79
[2] https://github.com/KSPP/linux/issues/86

Tested-by: kernel test robot <lkp@intel.com>
Link: https://github.com/GustavoARSilva/linux-hardening/blob/master/cii/0-day/tty-20200716.md
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/tty/tty_io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5a6f36b391d9..505bcba5ee02 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2683,7 +2683,7 @@ struct serial_struct32 {
         compat_int_t    baud_base;
         unsigned short  close_delay;
         char    io_type;
-        char    reserved_char[1];
+	char    reserved_char;
         compat_int_t    hub6;
         unsigned short  closing_wait; /* time to wait before closing */
         unsigned short  closing_wait2; /* no longer used... */
@@ -2691,7 +2691,7 @@ struct serial_struct32 {
         unsigned short  iomem_reg_shift;
         unsigned int    port_high;
      /* compat_ulong_t  iomap_base FIXME */
-        compat_int_t    reserved[1];
+	compat_int_t    reserved;
 };
 
 static int compat_tty_tiocsserial(struct tty_struct *tty,
@@ -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));
@@ -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;
-- 
2.27.0


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

* Re: [PATCH][next] tty: Avoid the use of one-element arrays
  2020-07-16 18:08 [PATCH][next] tty: Avoid the use of one-element arrays Gustavo A. R. Silva
@ 2020-07-17  6:10 ` Jiri Slaby
  2020-07-22 18:24   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Slaby @ 2020-07-17  6:10 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Greg Kroah-Hartman; +Cc: linux-kernel

On 16. 07. 20, 20:08, Gustavo A. R. Silva wrote:
> 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;$

May I ask you to send a follow-up patch to fix the whole structure's
indentation?

> [1] https://github.com/KSPP/linux/issues/79
> [2] https://github.com/KSPP/linux/issues/86
> 
> Tested-by: kernel test robot <lkp@intel.com>
> Link: https://github.com/GustavoARSilva/linux-hardening/blob/master/cii/0-day/tty-20200716.md
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Acked-by: Jiri Slaby <jirislaby@kernel.org>

thanks,
-- 
js
suse labs

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

* Re: [PATCH][next] tty: Avoid the use of one-element arrays
  2020-07-17  6:10 ` Jiri Slaby
@ 2020-07-22 18:24   ` Gustavo A. R. Silva
  2020-07-23  6:30     ` Jiri Slaby
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-22 18:24 UTC (permalink / raw)
  To: Jiri Slaby, Gustavo A. R. Silva, Greg Kroah-Hartman; +Cc: linux-kernel



On 7/17/20 01:10, Jiri Slaby wrote:
> On 16. 07. 20, 20:08, Gustavo A. R. Silva wrote:
>> 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;$
> 
> May I ask you to send a follow-up patch to fix the whole structure's
> indentation?
> 

Hi Jiri,

Sure thing. I'll fix that up and send v2, shortly.

Thanks
--
Gustavo

>> [1] https://github.com/KSPP/linux/issues/79
>> [2] https://github.com/KSPP/linux/issues/86
>>
>> Tested-by: kernel test robot <lkp@intel.com>
>> Link: https://github.com/GustavoARSilva/linux-hardening/blob/master/cii/0-day/tty-20200716.md
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 
> Acked-by: Jiri Slaby <jirislaby@kernel.org>
> 
> thanks,
> 

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

* Re: [PATCH][next] tty: Avoid the use of one-element arrays
  2020-07-22 18:24   ` Gustavo A. R. Silva
@ 2020-07-23  6:30     ` Jiri Slaby
  2020-07-23  8:32       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Slaby @ 2020-07-23  6:30 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Gustavo A. R. Silva, Greg Kroah-Hartman; +Cc: linux-kernel

On 22. 07. 20, 20:24, Gustavo A. R. Silva wrote:
> 
> 
> On 7/17/20 01:10, Jiri Slaby wrote:
>> On 16. 07. 20, 20:08, Gustavo A. R. Silva wrote:
>>> 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;$
>>
>> May I ask you to send a follow-up patch to fix the whole structure's
>> indentation?
>>
> 
> Hi Jiri,
> 
> Sure thing. I'll fix that up and send v2, shortly.

Hi,

by a follow-up patch I meant a separate patch. Looking at it once again,
I would do 3 patches:
1) remove [1] arrays
2) change sizeofs
3) fix white space

thanks,
-- 
js
suse labs

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

* Re: [PATCH][next] tty: Avoid the use of one-element arrays
  2020-07-23  6:30     ` Jiri Slaby
@ 2020-07-23  8:32       ` Greg Kroah-Hartman
  2020-07-23 13:47         ` Gustavo A. R. Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-07-23  8:32 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Gustavo A. R. Silva, Gustavo A. R. Silva, linux-kernel

On Thu, Jul 23, 2020 at 08:30:47AM +0200, Jiri Slaby wrote:
> On 22. 07. 20, 20:24, Gustavo A. R. Silva wrote:
> > 
> > 
> > On 7/17/20 01:10, Jiri Slaby wrote:
> >> On 16. 07. 20, 20:08, Gustavo A. R. Silva wrote:
> >>> 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;$
> >>
> >> May I ask you to send a follow-up patch to fix the whole structure's
> >> indentation?
> >>
> > 
> > Hi Jiri,
> > 
> > Sure thing. I'll fix that up and send v2, shortly.
> 
> Hi,
> 
> by a follow-up patch I meant a separate patch. Looking at it once again,
> I would do 3 patches:
> 1) remove [1] arrays
> 2) change sizeofs
> 3) fix white space

I agree, that would be the ideal series.

thanks,

greg k-h

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

* Re: [PATCH][next] tty: Avoid the use of one-element arrays
  2020-07-23  8:32       ` Greg Kroah-Hartman
@ 2020-07-23 13:47         ` Gustavo A. R. Silva
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-23 13:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: Gustavo A. R. Silva, linux-kernel



On 7/23/20 03:32, Greg Kroah-Hartman wrote:
> On Thu, Jul 23, 2020 at 08:30:47AM +0200, Jiri Slaby wrote:
>> On 22. 07. 20, 20:24, Gustavo A. R. Silva wrote:
>>>
>>>
>>> On 7/17/20 01:10, Jiri Slaby wrote:
>>>> On 16. 07. 20, 20:08, Gustavo A. R. Silva wrote:
>>>>> 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;$
>>>>
>>>> May I ask you to send a follow-up patch to fix the whole structure's
>>>> indentation?
>>>>
>>>
>>> Hi Jiri,
>>>
>>> Sure thing. I'll fix that up and send v2, shortly.
>>
>> Hi,
>>
>> by a follow-up patch I meant a separate patch. Looking at it once again,
>> I would do 3 patches:
>> 1) remove [1] arrays
>> 2) change sizeofs
>> 3) fix white space
> 
> I agree, that would be the ideal series.
> 

OK. No problem. I'll turn this into a patch series then. :)

Thanks
--
Gustavo

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

end of thread, other threads:[~2020-07-23 13:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 18:08 [PATCH][next] tty: Avoid the use of one-element arrays Gustavo A. R. Silva
2020-07-17  6:10 ` Jiri Slaby
2020-07-22 18:24   ` Gustavo A. R. Silva
2020-07-23  6:30     ` Jiri Slaby
2020-07-23  8:32       ` Greg Kroah-Hartman
2020-07-23 13:47         ` Gustavo A. R. Silva

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