Skip to contentSkip to conversation

ntsync: Check wait count based on byte size.

PATCH In review Elizabeth Figura 2 participants 3 messages Feb 20, 2025 – Feb 21, 2025

Subsystems (3)
lore
Share & tools
lore

Elizabeth Figura

author maintainer
#0 lore raw

PATCH v2 1/1 ntsync: Check wait count based on byte size.

GCC versions below 13 incorrectly detect the copy size as being static and too small to fit in the "fds" array. Work around this by explicitly calculating the size and returning EINVAL based on that, instead of based on the object count.

--

Suggested-by as per Arnd's request, but the only thing I changed was preserving array_size() [as noted by Geert in the linked thread]. I tested and found no regressions.

v2: Add missing sign-off

---
 drivers/misc/ntsync.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/misc/ntsync.c +3 -3
index 586b86243e1d..24cb2f71186a 100644
@@ -873,6 +873,7 @@ static int setup_wait(struct ntsync_device *dev,
 {
 	int fds[NTSYNC_MAX_WAIT_COUNT + 1];
 	const __u32 count = args->count;
+	size_t size = array_size(count, sizeof(fds[0]));
 	struct ntsync_q *q;
 	__u32 total_count;
 	__u32 i, j;
@@ -880,15 +881,14 @@ static int setup_wait(struct ntsync_device *dev,
 	if (args->pad || (args->flags & ~NTSYNC_WAIT_REALTIME))
 		return -EINVAL;
 
-	if (args->count > NTSYNC_MAX_WAIT_COUNT)
+	if (size >= sizeof(fds))
 		return -EINVAL;
 
 	total_count = count;
 	if (args->alert)
 		total_count++;
 
-	if (copy_from_user(fds, u64_to_user_ptr(args->objs),
-			   array_size(count, sizeof(*fds))))
+	if (copy_from_user(fds, u64_to_user_ptr(args->objs), size))
 		return -EFAULT;
 	if (args->alert)
 		fds[count] = args->alert;
Signature · 1 line
2.47.2
author maintainer
#1 lore raw
Quoted 9 lines · On Thursday, 20 February 2025 13:23:34 CST Elizabeth Figura wrote:

GCC versions below 13 incorrectly detect the copy size as being static and too small to fit in the "fds" array. Work around this by explicitly calculating the size and returning EINVAL based on that, instead of based on the object count.

Oops, I forgot to include a reference to v1:

https://lore.kernel.org/all/[email protected]/

#2 lore raw
Quoted 11 lines · Elizabeth Figura
Quoted 9 lines · On Thursday, 20 February 2025 13:23:34 CST Elizabeth Figura wrote:

GCC versions below 13 incorrectly detect the copy size as being static and too small to fit in the "fds" array. Work around this by explicitly calculating the size and returning EINVAL based on that, instead of based on the object count.

Quoted 3 lines

Oops, I forgot to include a reference to v1:

https://lore.kernel.org/all/[email protected]/

No need for the reference, that's easy enough to find if I needed it.

thanks,

greg k-h