From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25EB353BE for ; Wed, 3 Jul 2024 01:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719969892; cv=none; b=mTcSmQwR+XaskHriuX1TonrFmU1RWMaux7kGzYD/pYK/N6bwNvxS2Y0FSqhKu03+5QFi1mBSB1Z/nmdjnYFdWMQ0xMHUd4nzC1Zj/jSsMiKsgd6n2CTm+9Mc5ltb/L+Uj+YAMfEMmcngx0JcfeadCpftFuN+lqFhpGfkWzOImps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719969892; c=relaxed/simple; bh=hVJFtsQLStwaNgFureVv0oR1O+Ev1bYFBNSi90GSxpI=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=n5ir3el0Ez6pUku9Oi3vbaIRaNppbQg4BWMpU9h/Tv4pBJ9mB+MDr9Lr4pfWOMG+gvoa6DoylFz8BKRi+fwUWGw/eqAERo5V/pOL8uDBi0YRKgJG76R1sXwDPDigchqvzmNVn3l5alNzleAZeyrFixat7Rbt92aopgONrPZq1PU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.136 Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B7B3360C24 for ; Wed, 3 Jul 2024 01:24:50 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -4.199 X-Spam-Level: Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id mH6qIq1qEE-e for ; Wed, 3 Jul 2024 01:24:49 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.187; helo=szxga01-in.huawei.com; envelope-from=yi.zhang@huawei.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 1AC8F60BD4 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1AC8F60BD4 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1AC8F60BD4 for ; Wed, 3 Jul 2024 01:24:47 +0000 (UTC) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WDMQm2k5xzxTbX; Wed, 3 Jul 2024 09:20:16 +0800 (CST) Received: from kwepemf100017.china.huawei.com (unknown [7.202.181.16]) by mail.maildlp.com (Postfix) with ESMTPS id 6FD191402CE; Wed, 3 Jul 2024 09:24:43 +0800 (CST) Received: from [10.174.179.80] (10.174.179.80) by kwepemf100017.china.huawei.com (7.202.181.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 3 Jul 2024 09:24:42 +0800 Subject: Re: [PATCH v2] Fix WARNING in __ext4_ioctl To: Pei Li CC: , , , , , , Theodore Ts'o , Andreas Dilger References: <20240702-bug8-v2-1-be675f490db1@gmail.com> From: Zhang Yi Message-ID: <154c52ab-2452-df90-a8d8-5b786f46041b@huawei.com> Date: Wed, 3 Jul 2024 09:24:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-kernel-mentees@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240702-bug8-v2-1-be675f490db1@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemf100017.china.huawei.com (7.202.181.16) On 2024/7/3 8:07, Pei Li wrote: > Specify the size of s_volume_name in strscpy_pad() to avoid buffer > overflow. > > strscpy_pad() by default takes the size of destination string as the > size to be read from source string. However, as s_volume_name is only > declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more > than expected. > > Reported-by: syzbot+2cab87506a0e7885f4b9@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=2cab87506a0e7885f4b9 > Fixes: 744a56389f73 ("ext4: replace deprecated strncpy with alternatives") > Signed-off-by: Pei Li Thanks for the fix, it looks good to me. Reviewed-by: Zhang Yi > --- > strscpy_pad() by default takes the size of destination string as the > size to be read from source string. However, as s_volume_name is only > declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more > than expected. > > Specify the size of s_volume_name in strscpy_pad() to avoid buffer > overflow. > --- > Changes in v2: > - Add fixes label > - Move workaround into commit log > - Link to v1: https://lore.kernel.org/r/20240628-bug8-v1-1-417ef53cca33@gmail.com > --- > fs/ext4/ioctl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c > index dab7acd49709..0c4fb579757a 100644 > --- a/fs/ext4/ioctl.c > +++ b/fs/ext4/ioctl.c > @@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_label > BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX); > > lock_buffer(sbi->s_sbh); > - strscpy_pad(label, sbi->s_es->s_volume_name); > + strscpy_pad(label, sbi->s_es->s_volume_name, EXT4_LABEL_MAX); > unlock_buffer(sbi->s_sbh); > > if (copy_to_user(user_label, label, sizeof(label))) > > --- > base-commit: 55027e689933ba2e64f3d245fb1ff185b3e7fc81 > change-id: 20240628-bug8-7f700a228c4a > > Best regards, >