Skip to contentSkip to conversation

block: scsi_ioctl: Avoid the use of one-element arrays

PATCH In review Gustavo A. R. Silva 3 participants 6 messages Oct 2, 2020 – Oct 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: scsi_ioctl: Avoid the use of one-element arrays

One-element arrays are being deprecated[1]. Replace the one-element array with a simple object of type compat_caddr_t: 'compat_caddr_t unused'[2], once it seems this field is actually never used.

Also, update struct cdrom_generic_command in UAPI by adding an anonimous union to avoid using the one-element array _reserved_.

[1] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://github.com/KSPP/linux/issues/86

---
 block/scsi_ioctl.c         | 6 +++---
 include/uapi/linux/cdrom.h | 5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
block/scsi_ioctl.c +3 -3
index 600e38cb69b2..2dfb699389df 100644
@@ -643,7 +643,7 @@ struct compat_cdrom_generic_command {
 	unsigned char	data_direction;
 	compat_int_t	quiet;
 	compat_int_t	timeout;
-	compat_caddr_t	reserved[1];
+	compat_caddr_t	unused;
 };
 #endif
 
@@ -665,7 +665,7 @@ static int scsi_get_cdrom_generic_arg(struct cdrom_generic_command *cgc,
 			.data_direction	= cgc32.data_direction,
 			.quiet		= cgc32.quiet,
 			.timeout	= cgc32.timeout,
-			.reserved[0]	= compat_ptr(cgc32.reserved[0]),
+			.unused		= compat_ptr(cgc32.unused),
 		};
 		memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE);
 		return 0;
@@ -690,7 +690,7 @@ static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc,
 			.data_direction	= cgc->data_direction,
 			.quiet		= cgc->quiet,
 			.timeout	= cgc->timeout,
-			.reserved[0]	= (uintptr_t)(cgc->reserved[0]),
+			.unused		= (uintptr_t)(cgc->unused),
 		};
 		memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE);
 
include/uapi/linux/cdrom.h +4 -1
index 2817230148fd..6c34f6e2f1f7 100644
@@ -289,7 +289,10 @@ struct cdrom_generic_command
 	unsigned char		data_direction;
 	int			quiet;
 	int			timeout;
-	void			__user *reserved[1];	/* unused, actually */
+	union {
+		void		__user *reserved[1];	/* unused, actually */
+		void            __user *unused;
+	};
 };
 
 /*
Signature · 1 line
2.27.0
maintainer
#1 lore raw

include/uapi/linux/cdrom.h struct cdrom_generic_command · line 295

Quoted 13 lines · Gustavo A. R. Silva
include/uapi/linux/cdrom.h +4 -1
index 2817230148fd..6c34f6e2f1f7 100644
@@ -289,7 +289,10 @@ struct cdrom_generic_command
 	unsigned char		data_direction;
 	int			quiet;
 	int			timeout;
-	void			__user *reserved[1];	/* unused, actually */
+	union {
+		void		__user *reserved[1];	/* unused, actually */
+		void            __user *unused;
+	};

What's the point of this union, why not just turn it into

	void *			__user *unused;

?

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 17 lines · Jens Axboe

include/uapi/linux/cdrom.h struct cdrom_generic_command · line 295

Quoted 13 lines · Gustavo A. R. Silva
include/uapi/linux/cdrom.h +4 -1
index 2817230148fd..6c34f6e2f1f7 100644
@@ -289,7 +289,10 @@ struct cdrom_generic_command
 	unsigned char		data_direction;
 	int			quiet;
 	int			timeout;
-	void			__user *reserved[1];	/* unused, actually */
+	union {
+		void		__user *reserved[1];	/* unused, actually */
+		void            __user *unused;
+	};

What's the point of this union, why not just turn it into

Quoted 3 lines
	void *			__user *unused;

?

I just don't want to take any chances of breaking any user-space application that, for some reason, may be considering that field.

--
Gustavo

maintainer
#3 lore raw
Quoted 18 lines · Gustavo A. R. Silva
Quoted 17 lines · Jens Axboe

include/uapi/linux/cdrom.h struct cdrom_generic_command · line 295

Quoted 13 lines · Gustavo A. R. Silva
include/uapi/linux/cdrom.h +4 -1
index 2817230148fd..6c34f6e2f1f7 100644
@@ -289,7 +289,10 @@ struct cdrom_generic_command
 	unsigned char		data_direction;
 	int			quiet;
 	int			timeout;
-	void			__user *reserved[1];	/* unused, actually */
+	union {
+		void		__user *reserved[1];	/* unused, actually */
+		void            __user *unused;
+	};

What's the point of this union, why not just turn it into

Quoted 6 lines
Quoted 3 lines
	void *			__user *unused;

?

I just don't want to take any chances of breaking any user-space application that, for some reason, may be considering that field.

I guess that's a valid concern, who knows what applications are doing to an ignored field.

I'll apply it, thanks.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 12 lines · Jens Axboe
Quoted 12 lines
Quoted 11 lines

include/uapi/linux/cdrom.h struct cdrom_generic_command · line 295

Quoted 5 lines
include/uapi/linux/cdrom.h +4 -1
-	void			__user *reserved[1];	/* unused, actually */
+	union {
+		void		__user *reserved[1];	/* unused, actually */
+		void            __user *unused;
+	};

What's the point of this union, why not just turn it into

	void *			__user *unused;

?

Quoted 7 lines
Quoted 2 lines

I just don't want to take any chances of breaking any user-space application that, for some reason, may be considering that field.

I guess that's a valid concern, who knows what applications are doing to an ignored field.

I'll apply it, thanks.

Awesome. :)

Thanks.
--
Gustavo

#5 lore raw
In reply to Gustavo A. R. Silva
Quoted 3 lines · Gustavo A. R. Silva

One-element arrays are being deprecated[1]. Replace the one-element array with a simple object of type compat_caddr_t: 'compat_caddr_t unused'[2], once it seems this field is actually never used.

They are only deprecated when abused as variable length array. That is not the case here.