Skip to content

Commit 7eefbb5

Browse files
Elizabeth FiguraWangYuli
authored andcommitted
ntsync: Check wait count based on byte size.
[ Upstream commit 92527e4 ] 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> [ Backport from v6.14 ] Signed-off-by: WangYuli <wangyuli@uniontech.com>
1 parent 75b14ec commit 7eefbb5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/misc/ntsync.c

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

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

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

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

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

0 commit comments

Comments
 (0)