]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ptp: Add a upper bound on max_vclocks
authorI Viswanath <viswanathiyyappan@gmail.com>
Thu, 25 Sep 2025 15:59:08 +0000 (21:29 +0530)
committerJakub Kicinski <kuba@kernel.org>
Fri, 26 Sep 2025 22:30:31 +0000 (15:30 -0700)
syzbot reported WARNING in max_vclocks_store.

This occurs when the argument max is too large for kcalloc to handle.

Extend the guard to guard against values that are too large for
kcalloc

Reported-by: syzbot+94d20db923b9f51be0df@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=94d20db923b9f51be0df
Tested-by: syzbot+94d20db923b9f51be0df@syzkaller.appspotmail.com
Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion")
Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Link: https://patch.msgid.link/20250925155908.5034-1-viswanathiyyappan@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/ptp/ptp_private.h
drivers/ptp/ptp_sysfs.c

index b352df4cd3f972855d9539ccbe14ff54c2092985..f329263f33aa127d6f3bbe129ef3dc52670da7c4 100644 (file)
@@ -22,6 +22,7 @@
 #define PTP_MAX_TIMESTAMPS 128
 #define PTP_BUF_TIMESTAMPS 30
 #define PTP_DEFAULT_MAX_VCLOCKS 20
+#define PTP_MAX_VCLOCKS_LIMIT (KMALLOC_MAX_SIZE/(sizeof(int)))
 #define PTP_MAX_CHANNELS 2048
 
 enum {
index 6b1b8f57cd9510f269c86dd89a7a74f277f6916b..200eaf50069681eecc87d63c0e0440f28cccab77 100644 (file)
@@ -284,7 +284,7 @@ static ssize_t max_vclocks_store(struct device *dev,
        size_t size;
        u32 max;
 
-       if (kstrtou32(buf, 0, &max) || max == 0)
+       if (kstrtou32(buf, 0, &max) || max == 0 || max > PTP_MAX_VCLOCKS_LIMIT)
                return -EINVAL;
 
        if (max == ptp->max_vclocks)