From nobody Wed Oct 1 23:32:11 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5730A302760 for ; Thu, 25 Sep 2025 15:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758815966; cv=none; b=eSdMsygyw82R9VaDiCs9K4Bxp5MwzhX9xe5tXJ55qS5L0iuYxaHqmIGBim5voypfxzbNER0Vw/wLJMWW9Dh1QfZ5DMncBAVynqYSXFWo9M5XWzsb/z2p3TZCKjSsA15L4jIYQEx24f40rCr+50ZN4r34jGgW/Ft7p3YPEEUd8rA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758815966; c=relaxed/simple; bh=2eZlHWvOxIgL3EbW7gHH6le+1fHOsCXZEgZKoMQwuOU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LW/xd44iQZqdihWsBLfzHr9yDLTnPUEWUBTbzYpgTDr8+Es29Hz4vx+OXHA+I4y3nPNfDm3wZHRQ8cSZjQ/ULMPgp+PnGx1Zh0htOORZvUZXdjjTcKSV99dzBUddGrYRgRleTbalS4vmv4xyfpGPr8qPyisZ7dCSEJgqVwUC6Js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DoYNbEM5; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DoYNbEM5" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-77f32d99a97so1172706b3a.1 for ; Thu, 25 Sep 2025 08:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758815964; x=1759420764; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0haNpnskPhHv+Hqq/prkArlkxvbNwI7IdrC7Jtj5DeM=; b=DoYNbEM5TpV3Z17OMjOy0uqsyvDFPyTPoxJtD1dejAxtus7VVtREu/92QrEICzDkak XXHXWYZEGsj8SojYj8cs+ADE0O0xLL8+UmwqzvENiIpKQDxYGu6SomHWrffZEBP4dcek reXpACfda0+NllIHbcuELyWIu6iUwFchCkquLQ2Y7JaAc9WgqDkUcsA6cESIu2CMp69d kArKgaYRi8NKfSg/UidWeR4WC8difCzB2ERHOvDaASUPTfT6eUsNQuj3J9JI8pXI9p/x MvVf/xn0SE64gdKi/I/WJohf0+W2Nxz7III1vOIcijBlUX7agCOSgaLQepFc7z2b9GfD YCZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758815964; x=1759420764; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0haNpnskPhHv+Hqq/prkArlkxvbNwI7IdrC7Jtj5DeM=; b=gXj9SzL7iJpuD1Lq/eN6u3HZFTipkoLQzWIExJcnZ+K867XWNrnKXHSHEyRHRh4o9+ 1mAzszpTxKfpn3VW8ur6oC0wUiLBRQA1P20jzpoVvOSyjAJ9t1UsD9u4hzP4PTkHu3IF rsnqot6gpHUO9Y3dKhzqBTFFFmJdK/Zxyh6ExVxk3n6oVbAYR5clAdbMsBm+wo4rIl/2 y1wGfAj18FfgCs23G30OTM5LCNR0riiDzvlDu8CJG2FXg1YgWClPzcXU2WvWxUAZUd1/ jnes1dmlZ44+++trtoFc8HVTZcQYmCee1meZ0voZ83jZP+jfwz1coW74SdusRnet1h+j e9WQ== X-Forwarded-Encrypted: i=1; AJvYcCWLTfxUNg2ZnJa72b7nzou5OiIqZ49jAT4PjpdBZZ40C8y8ntyXwyvKEX5LnQJOEwLh0LZzVxcflUJYmBs=@vger.kernel.org X-Gm-Message-State: AOJu0YxLY1B01zPq0trpky1LCVx19jkiUFOGU+D7xWYdoA6alQCcKASn OgNbrF7bcbbssfehQztA9vLGT37KIoLMtp364Vys5B9WXcZzAOln4A+L X-Gm-Gg: ASbGncuBluswTuIEhuUdMxE8TwiR70deKEGng8plFq7IE86ILnoqt+pcm/aTdz3XWY+ JVkM/JGQBthl/dgOExlKeAjsl9pGLQYc0lzM3eVAbE/dpfCrLQZCB6Gcv2ATLPJpoJieJJAcfoa n6TCaQRnsOO3bzE5LOj1/qlqyqBX9yAQ90ULZ/6chmnXNPm8l4+7+cJlSA+BHxz8Zu6CXKoMGxQ 9iDYFht2tdoAr9Wvs7t6PQ21eOBJSOXCSrnEspcJR3Ty7ex+oygmXg3dwuilPTJODbgPp+kb5NB 9a3ZTiRc5qHSUkxEDWIhoLk1xkRwHOkr4Q4d1zblnrGRwF9UI5q80NcDptUUl03pdxIhO9UnP+v g8xiqQ/a5oR7Q400DRl6I7WK+9hYUvVuONxwfnyvY8HyzIfBXFYq1dU6hpW9+vZjy+Mne60Z1Rx DyQnft3HDiy1GQ X-Google-Smtp-Source: AGHT+IEhAQcRgo74RGno0MIUNQs86Uz784EwSabYzAQVGz1THpiA0aDqQT0LiijW0GN3h3wpllQpcA== X-Received: by 2002:a05:6a21:207:b0:2ed:997b:44b5 with SMTP id adf61e73a8af0-2ed997b52c3mr1885758637.37.1758815964344; Thu, 25 Sep 2025 08:59:24 -0700 (PDT) Received: from debian.domain.name ([223.181.105.26]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7810238cafasm2320354b3a.4.2025.09.25.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Sep 2025 08:59:23 -0700 (PDT) From: I Viswanath To: richardcochran@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev, david.hunter.linux@gmail.com, I Viswanath , syzbot+94d20db923b9f51be0df@syzkaller.appspotmail.com Subject: [PATCH net v3] ptp: Add a upper bound on max_vclocks Date: Thu, 25 Sep 2025 21:29:08 +0530 Message-ID: <20250925155908.5034-1-viswanathiyyappan@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D94d20db923b9f51be0df Tested-by: syzbot+94d20db923b9f51be0df@syzkaller.appspotmail.com Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion") Signed-off-by: I Viswanath Acked-by: Richard Cochran --- This can be reproduced by executing:=20 echo x > /sys/devices/virtual/ptp/ptp0/max_vclocks where x > KMALLOC_MAX_SIZE/(sizeof(int)) which computes to 1048576 on my system What would be a reasonable value for PTP_MAX_VCLOCKS_LIMIT? KMALLOC_MAX_SIZE/(sizeof(int)) is the absolute max value for which the=20 memory allocation won't fail v1: Link: https://lore.kernel.org/linux-mm/20250922170357.148588-1-viswanathiyy= appan@gmail.com/ v2: - Moved the validation to max_vclocks_store Link: https://lore.kernel.org/netdev/20250923160622.8096-1-viswanathiyyappa= n@gmail.com/ v3: - Removed RFC tag from the patch drivers/ptp/ptp_private.h | 1 + drivers/ptp/ptp_sysfs.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index b352df4cd3f9..f329263f33aa 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -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 =20 enum { diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 6b1b8f57cd95..200eaf500696 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -284,7 +284,7 @@ static ssize_t max_vclocks_store(struct device *dev, size_t size; u32 max; =20 - if (kstrtou32(buf, 0, &max) || max =3D=3D 0) + if (kstrtou32(buf, 0, &max) || max =3D=3D 0 || max > PTP_MAX_VCLOCKS_LIMI= T) return -EINVAL; =20 if (max =3D=3D ptp->max_vclocks) --=20 2.47.3