Skip to content

Commit 92527e4

Browse files
Elizabeth Figuragregkh
authored andcommitted
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. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202502072019.LYoCR9bF-lkp@intel.com/ Suggested-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com> -- 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 Link: https://lore.kernel.org/r/20250220192334.549167-1-zfigura@codeweavers.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 32ce5d8 commit 92527e4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/misc/ntsync.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,22 +873,22 @@ static int setup_wait(struct ntsync_device *dev,
873873
{
874874
int fds[NTSYNC_MAX_WAIT_COUNT + 1];
875875
const __u32 count = args->count;
876+
size_t size = array_size(count, sizeof(fds[0]));
876877
struct ntsync_q *q;
877878
__u32 total_count;
878879
__u32 i, j;
879880

880881
if (args->pad || (args->flags & ~NTSYNC_WAIT_REALTIME))
881882
return -EINVAL;
882883

883-
if (args->count > NTSYNC_MAX_WAIT_COUNT)
884+
if (size >= sizeof(fds))
884885
return -EINVAL;
885886

886887
total_count = count;
887888
if (args->alert)
888889
total_count++;
889890

890-
if (copy_from_user(fds, u64_to_user_ptr(args->objs),
891-
array_size(count, sizeof(*fds))))
891+
if (copy_from_user(fds, u64_to_user_ptr(args->objs), size))
892892
return -EFAULT;
893893
if (args->alert)
894894
fds[count] = args->alert;

0 commit comments

Comments
 (0)