Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3353451pxv; Mon, 28 Jun 2021 02:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7Ga+wi9fXIblihU6cDCy46NLASrlg2ZNhOaU4axzKpzemmL0oMfek6BhhArS53z753F90 X-Received: by 2002:aa7:dc42:: with SMTP id g2mr31272807edu.362.1624873418984; Mon, 28 Jun 2021 02:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624873418; cv=none; d=google.com; s=arc-20160816; b=rtq75WuX40SYc04GC/Vjb3v3lK8+cbC6Vtc4stDzoKEquBDUdBOa7uocsHHE25Vcqw Ejz4unDjqo78YSbMTUZ83B6fhBfMQRtbkH47z+LR+bjUQWv7I/QTtPLOGT1OhvFN05Xr Q3L04xY+kPBjxV4reZgu7/Rgu+z+/W4ZmvbEU4V8EvRaPCN4JttOJ+aBAMbfUJfz3B3h uq52YeYZOClfp3GKY4DkZ/hOAAP7Q2WQGWm7wKLZwlcnCdcSJq4bDZK20TrlhznU91UC 8sPr4ObCdjVHNA3kNSTNceAsOyapxRXjeO4y1ZJYzB2+lTLKMDWCx4Z2inB4IE0czgu0 IYgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from; bh=aCt6xqGT9K/Yj98pmPSFNqe3fHem42N2LaUqSQp6l3Q=; b=ePElJFxOxDbwa5LIypSVH7kKfRaw1CzDm05A7Luk+9UomneydzkZZpVp2O2fn7Vlly OGdPhV0UMo+nqYLgzeMrro2b/1wJGKcDbQc5kDiw2j5cWEAzhNoUzbG2lzO8gSdAt1r6 uHkPdYc8RwvEVH9aWLSgaEtI7NstfTvjEQQzoNvtCR+iEkRilQBTHA3FM5+DKZRkXJKt w4EhgcLOQFJJWzf1oESd42gImnPKRbZ8255fAQ8B4BgcTB2BiAOuFzD/+Qy6nTUbbTNm F/qdleZIEkWeYoJ4Xfn6uVKU6IpxeZzx8s2N/4frKd2dncGODcYzvroBpF5nxq2nsP7w pzcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 1si13769643ejm.532.2021.06.28.02.43.15; Mon, 28 Jun 2021 02:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232512AbhF1Jnv convert rfc822-to-8bit (ORCPT + 99 others); Mon, 28 Jun 2021 05:43:51 -0400 Received: from mgw-02.mpynet.fi ([82.197.21.91]:49958 "EHLO mgw-02.mpynet.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232488AbhF1Jnu (ORCPT ); Mon, 28 Jun 2021 05:43:50 -0400 X-Greylist: delayed 1104 seconds by postgrey-1.27 at vger.kernel.org; Mon, 28 Jun 2021 05:43:49 EDT Received: from pps.filterd (mgw-02.mpynet.fi [127.0.0.1]) by mgw-02.mpynet.fi (8.16.0.43/8.16.0.43) with SMTP id 15S9M979115613; Mon, 28 Jun 2021 12:22:26 +0300 Received: from ex13.tuxera.com (ex13.tuxera.com [178.16.184.72]) by mgw-02.mpynet.fi with ESMTP id 39f9xh82tp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 12:22:25 +0300 Received: from tuxera-exch.ad.tuxera.com (10.20.48.11) by tuxera-exch.ad.tuxera.com (10.20.48.11) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 28 Jun 2021 12:22:25 +0300 Received: from tuxera-exch.ad.tuxera.com ([fe80::552a:f9f0:68c3:d789]) by tuxera-exch.ad.tuxera.com ([fe80::552a:f9f0:68c3:d789%12]) with mapi id 15.00.1497.018; Mon, 28 Jun 2021 12:22:25 +0300 From: Anton Altaparmakov To: Andrew Morton CC: "linux-ntfs-dev@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , "skhan@linuxfoundation.org" , "gregkh@linuxfoundation.org" , "linux-kernel-mentees@lists.linuxfoundation.org" , Desmond Cheong Zhi Xi , "syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com" Subject: Re: [PATCH] ntfs: Fix validity check for file name attribute Thread-Topic: [PATCH] ntfs: Fix validity check for file name attribute Thread-Index: AQHXYNr9xtdXtYfpBEGmty8mpcDGlaspCjOA Date: Mon, 28 Jun 2021 09:22:24 +0000 Message-ID: References: <20210614050540.289494-1-desmondcheongzx@gmail.com> In-Reply-To: <20210614050540.289494-1-desmondcheongzx@gmail.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [86.134.197.70] Content-Type: text/plain; charset="us-ascii" Content-ID: <99C2CF21868B1447B5C705333F109AC2@ex13.tuxera.com> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Proofpoint-GUID: Vo0XTbXZ_dePF2syDtdnkrOgOV9_0Wl2 X-Proofpoint-ORIG-GUID: Vo0XTbXZ_dePF2syDtdnkrOgOV9_0Wl2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-28_07:2021-06-25,2021-06-28 signatures=0 X-Proofpoint-Spam-Details: rule=mpy_notspam policy=mpy score=0 phishscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 suspectscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106280065 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, Please can you merge this patch? I am also marking it for stable. Thanks a lot in advance! Best regards, Anton --- When checking the file name attribute, we want to ensure that it fits within the bounds of ATTR_RECORD. To do this, we should check that (attr record + file name offset + file name length) < (attr record + attr record length). However, the original check did not include the file name offset in the calculation. This means that corrupted on-disk metadata might not caught by the incorrect file name check, and lead to an invalid memory access. An example can be seen in the crash report of a memory corruption error found by Syzbot: https://syzkaller.appspot.com/bug?id=a1a1e379b225812688566745c3e2f7242bffc246 Adding the file name offset to the validity check fixes this error and passes the Syzbot reproducer test. Reported-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com Tested-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com Signed-off-by: Desmond Cheong Zhi Xi Acked-by: Anton Altaparmakov Cc: stable@vger.kernel.org --- fs/ntfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index f5c058b3192c..4474adb393ca 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -477,7 +477,7 @@ static int ntfs_is_extended_system_file(ntfs_attr_search_ctx *ctx) } file_name_attr = (FILE_NAME_ATTR*)((u8*)attr + le16_to_cpu(attr->data.resident.value_offset)); - p2 = (u8*)attr + le32_to_cpu(attr->data.resident.value_length); + p2 = (u8 *)file_name_attr + le32_to_cpu(attr->data.resident.value_length); if (p2 < (u8*)attr || p2 > p) goto err_corrupt_attr; /* This attribute is ok, but is it in the $Extend directory? */ -- 2.25.1 -- Anton Altaparmakov (replace at with @) Lead in File System Development, Tuxera Inc., http://www.tuxera.com/ Linux NTFS maintainer