Message ID | 20240212083347.10742-1-d.dulov@aladdin.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2301657dyd; Mon, 12 Feb 2024 00:34:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmbLgsxYOdDhDUGt7yxkvLD/1U6bcKLS4cqUsZLyU24My44LQfNmeZYzoZaXi6F4Q6igE4 X-Received: by 2002:a2e:a238:0:b0:2d0:a037:b93d with SMTP id i24-20020a2ea238000000b002d0a037b93dmr4162274ljm.41.1707726865637; Mon, 12 Feb 2024 00:34:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707726865; cv=pass; d=google.com; s=arc-20160816; b=LXTPbkMaKd/yyWmvX8jWOeHq6qRUNNX4YXjPprVWuvZMYUrD4qI3nksWCyjZ9wYtZw Ue43yjltnEpU56+NsMHiGAn++v8EunAU2e8PfxuV6SW/MkhrLmax90vL1VoC0Pn32nBg p5xjIKickIx07Z+taPPusaRXP+HaLGY1jeRbrzRnf3x47Rm5y2cw4pqbALWw9+NJR0oZ v+XPjxRsOOD+ZJZegJs/8Tg/fekdTFmwlFoAbbCBZ3J//+DY5c0s92dbaaldJv4UyOlC PjZRaK98MeMKL21zmPRfwC/bYq+r+SXKYvzWGHlCu+U9sU2QVeL4/ji1RZ+0xxTjl7Y2 O3nA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=XCegJq6xKXjM5CeRe622d69Z9MiMsdpxzHiJq7nRdEk=; fh=JfZz0XRRRSriywe4fvzlEobsWB8I2NlnWsb0EgeDYD4=; b=FqktDEBNnaK0qz0vAW2Fo12kkepj2OuFdzJvdIFP+3B04zpLtBG2h14oTZByLOeh1W b1DpzQGctbKn7pXWbDzVQoyOWUWfJMYqJUcRyc/7E+y0UwaJIxo5TmwreMNVAMaaeSS9 PnbBptG1/+bnK98pC0xuAIuxCW7ep4i1b9cJwcjporHUqgfc1EdVQmycqscWZt3a6/SO kC7hytANo08JQODF2cu+B3N5tbarStel7Ye42IFYjL8DdZ1OUPBTB8Po2kt9jNrfaENc nGph5Qz2ldYrgrOYFbj49e6SZCL0g/FS+o2Y9v3mlbNF+bzdTEGbW+S1nsJsjrObcBq6 ULFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru X-Forwarded-Encrypted: i=2; AJvYcCW6fLWl/BHb93QC8El8je0BTtctyxEbWocL0pyc8LfvUkymY2vkgY0R15WD2Rf1/InA9MvaG6NSmB6GBZb9jtcv/kcSwQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b15-20020aa7cd0f000000b0056119abcd45si2552419edw.611.2024.02.12.00.34.25 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:34:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aladdin.ru dmarc=pass fromdomain=aladdin.ru); spf=pass (google.com: domain of linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61204-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 40F451F25FFE for <ouuuleilei@gmail.com>; Mon, 12 Feb 2024 08:34:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8C90F9E5; Mon, 12 Feb 2024 08:34:10 +0000 (UTC) Received: from mail-out.aladdin-rd.ru (mail-out.aladdin-rd.ru [91.199.251.16]) (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 61B4B101C1 for <linux-kernel@vger.kernel.org>; Mon, 12 Feb 2024 08:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.199.251.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707726849; cv=none; b=t8AXb8DYIZY2BhEXXD5HckfyiVJTtOtIMwl9dYr/UyCrJ4G8o6wqr9WD5XVJNzvCt1Zs+h4gqTBfrly1g6Hd+8wAJF4eeDkUwl/q1bH/eQHa8VYvbxZTDUjTvCVYYvee62LiDEr/wue2mQwKruJg3vJ7tG+9hhIg1k5Q5ZJgFIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707726849; c=relaxed/simple; bh=Ppw/szsqkGDaYnrWnVR/G4gm/cVWMG7SAB9kfoPViIc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ULTeK0nOi+6GsNLQKR1KCRFsf8TIalyTF82KJlBj63B7JHG1T9TM3buXKm3MIo29oi05RxFLTedbhQbTiTgdIfgaqQ1zxA3UGUdYC8+iBRzxCFvIx8/mGKe88oo7Ocd7L+ODstZSyH0IE8V3r4ANL5e9n0cHCusru9VqrglitRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru; spf=pass smtp.mailfrom=aladdin.ru; arc=none smtp.client-ip=91.199.251.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=aladdin.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aladdin.ru From: Daniil Dulov <d.dulov@aladdin.ru> To: Jeffrey E Altman <jaltman@auristor.com> CC: Daniil Dulov <d.dulov@aladdin.ru>, <linux-afs@lists.infradead.org>, Marc Dionne <marc.dionne@auristor.com>, David Howells <dhowells@redhat.com>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org> Subject: [PATCH v2] afs: Increase buffer size in afs_update_volume_status() Date: Mon, 12 Feb 2024 00:33:47 -0800 Message-ID: <20240212083347.10742-1-d.dulov@aladdin.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-2016-02.aladdin.ru (192.168.1.102) To EXCH-2016-01.aladdin.ru (192.168.1.101) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790616435595540906 X-GMAIL-MSGID: 1790681405722411166 |
Series |
[v2] afs: Increase buffer size in afs_update_volume_status()
|
|
Commit Message
Daniil Dulov
Feb. 12, 2024, 8:33 a.m. UTC
The max length of volume->vid value is 20 characters.
So increase idbuf[] size up to 20 to avoid overflow.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation")
Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
fs/afs/volume.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 2/12/2024 3:33 AM, Daniil Dulov wrote: > The max length of volume->vid value is 20 characters. > So increase idbuf[] size up to 20 to avoid overflow. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: d2ddc776a458 ("afs: Overhaul volume and server record caching and fileserver rotation") > Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru> > --- > fs/afs/volume.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/afs/volume.c b/fs/afs/volume.c > index 020ecd45e476..d4a379bfd54e 100644 > --- a/fs/afs/volume.c > +++ b/fs/afs/volume.c > @@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key) > { > struct afs_server_list *new, *old, *discard; > struct afs_vldb_entry *vldb; > - char idbuf[16]; > + char idbuf[20]; > int ret, idsz; > > _enter(""); Reviewed-by: Jeffrey Altman <jaltman@auristor.com>
Daniil Dulov <d.dulov@aladdin.ru> wrote: > The max length of volume->vid value is 20 characters. > So increase idbuf[] size up to 20 to avoid overflow. Is that 20 including the NUL? If not, I'd increase it to 24 (it's likely to get rounded up to a multiple of 4 or 8 by the compiler). David
I suggest the attached instead. David --- diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 020ecd45e476..af3a3f57c1b3 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key) { struct afs_server_list *new, *old, *discard; struct afs_vldb_entry *vldb; - char idbuf[16]; + char idbuf[24]; int ret, idsz; _enter(""); @@ -361,7 +361,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key) /* We look up an ID by passing it as a decimal string in the * operation's name parameter. */ - idsz = sprintf(idbuf, "%llu", volume->vid); + idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid); vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz); if (IS_ERR(vldb)) {
Hello!
Thank you for your feedback. I agree with the suggested improvement. I will send v3 a bit later today.
-----Original Message-----
From: David Howells [mailto:dhowells@redhat.com]
Sent: Monday, February 19, 2024 1:34 PM
To: Daniil Dulov <D.Dulov@aladdin.ru>
Cc: dhowells@redhat.com; Jeffrey E Altman <jaltman@auristor.com>; linux-afs@lists.infradead.org; Marc Dionne <marc.dionne@auristor.com>; linux-kernel@vger.kernel.org; lvc-project@linuxtesting.org
Subject: Re: [PATCH v2] afs: Increase buffer size in afs_update_volume_status()
I suggest the attached instead.
David
---
diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 020ecd45e476..af3a3f57c1b3 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key) {
struct afs_server_list *new, *old, *discard;
struct afs_vldb_entry *vldb;
- char idbuf[16];
+ char idbuf[24];
int ret, idsz;
_enter("");
@@ -361,7 +361,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
/* We look up an ID by passing it as a decimal string in the
* operation's name parameter.
*/
- idsz = sprintf(idbuf, "%llu", volume->vid);
+ idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid);
vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz);
if (IS_ERR(vldb)) {
Daniil Dulov <D.Dulov@aladdin.ru> wrote:
> Thank you for your feedback. I agree with the suggested improvement. I will send v3 a bit later today.
I posted an updated patch:
https://lore.kernel.org/linux-fsdevel/20240219143906.138346-3-dhowells@redhat.com/T/#u
diff --git a/fs/afs/volume.c b/fs/afs/volume.c index 020ecd45e476..d4a379bfd54e 100644 --- a/fs/afs/volume.c +++ b/fs/afs/volume.c @@ -353,7 +353,7 @@ static int afs_update_volume_status(struct afs_volume *volume, struct key *key) { struct afs_server_list *new, *old, *discard; struct afs_vldb_entry *vldb; - char idbuf[16]; + char idbuf[20]; int ret, idsz; _enter("");