Skip to content

Commit e9f3529

Browse files
CraftyChimerakuba-moo
authored andcommitted
ptp: Add a upper bound on max_vclocks
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: 73f3706 ("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>
1 parent 958baf5 commit e9f3529

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

drivers/ptp/ptp_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define PTP_MAX_TIMESTAMPS 128
2323
#define PTP_BUF_TIMESTAMPS 30
2424
#define PTP_DEFAULT_MAX_VCLOCKS 20
25+
#define PTP_MAX_VCLOCKS_LIMIT (KMALLOC_MAX_SIZE/(sizeof(int)))
2526
#define PTP_MAX_CHANNELS 2048
2627

2728
enum {

drivers/ptp/ptp_sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static ssize_t max_vclocks_store(struct device *dev,
284284
size_t size;
285285
u32 max;
286286

287-
if (kstrtou32(buf, 0, &max) || max == 0)
287+
if (kstrtou32(buf, 0, &max) || max == 0 || max > PTP_MAX_VCLOCKS_LIMIT)
288288
return -EINVAL;
289289

290290
if (max == ptp->max_vclocks)

0 commit comments

Comments
 (0)