Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2717515pxv; Sun, 11 Jul 2021 23:40:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyqhqHDqVoyEPPPJuX/2BdczLXCfv4XeWn+Xb8ow6sXbPRm0rMTDiCAG4FL75CJW2vhLw1 X-Received: by 2002:a05:6402:1385:: with SMTP id b5mr48405884edv.276.1626072054399; Sun, 11 Jul 2021 23:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072054; cv=none; d=google.com; s=arc-20160816; b=MtcLlyUUoDrS0JCoZIOYg/KClg4iSH7f9Fb8oi8LGSHk0WTx9wcU+d5Zl06kfuan6n x+QYmxyQPaolT8qeS8AtHlHBboOg9Tx3o/9K1AamfnfTB2DJReKaghUw8z876Fhh2Ucd EINXfUP8vk3xEllcmcbdr1wEzeaO4OCZMgXtu52RGP1L53kMrk9C1l7hRBzCceW8vJFN D9X9Ra//D7Dmkcet4KTU+T6g/k9zyhyYGYMqawwKUIMgefgH7nucoeTLHg+4JvvI5Xpw sGiJPOhf3615l47MkeT8/dXNJugmfi8e8EPgpPk7KAGsO9BcGaf3ruoirtcd/N8rhJB0 pvmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9XU2zQ7YRk84itQ9pamurtOqttktN5NDNtRgQmc67G0=; b=RXdSzX6QV3J5E4jv4dPPc8SPfMAB4loGxG1j62KWRZijTeFIRpkLxA6xaMmWqV6dgt Pu43XtbCZj0knO1YXQie+8T84Pej+TPjJ83hcuCXOgFZ7APZPF0qJb2+gkdr5ofxSgmN /jHmSbXMCZyZ4M/O1m+82OktquOw9YEJ+Rm3orgTiVIIbNDWi9pNuhdwbZoSK6ZzKXvO 52Zb+JJp9UcIg7LtqM0oJSe42OKdeQgsfqX/3e1B0Pus+OLcCnmjWMzR/1574BO4s0SR VuHARPHtrZL1cKuifQ0XAxDP3wIzc/7ZnXY487WiJNzHjCAMib6fJSdNMt97QYG7Z1wO pHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="J0A1y/Oa"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si13020134edy.314.2021.07.11.23.40.31; Sun, 11 Jul 2021 23:40:54 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="J0A1y/Oa"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238648AbhGLGlj (ORCPT + 99 others); Mon, 12 Jul 2021 02:41:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:53450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237154AbhGLGeK (ORCPT ); Mon, 12 Jul 2021 02:34:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C62F610FA; Mon, 12 Jul 2021 06:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071431; bh=HlmL8ZEFf25jX5xlbAq1x65up61lml7RPN6niPzCn00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0A1y/Oafo0/ersXSY96xh8hvpOKHwoGulGdlMffBEm/FMunmYvPbtLDl9qjFeogS Sb4u9D+gxBezUQ20+hGjjeI4Xk9cpvK/dsQrkLIeE7bE/TDdceAOV35ofHTDoZGgRi w2tDEJWfFlbaXI/MLHkIy5FPt9dBPr8NR/sA2tY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Desmond Cheong Zhi Xi , syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com, Anton Altaparmakov , Shuah Khan , Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 029/593] ntfs: fix validity check for file name attribute Date: Mon, 12 Jul 2021 08:03:09 +0200 Message-Id: <20210712060846.378989803@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Desmond Cheong Zhi Xi commit d98e4d95411bbde2220a7afa38dcc9c14d71acbe upstream. 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. Link: https://lkml.kernel.org/r/20210614050540.289494-1-desmondcheongzx@gmail.com Signed-off-by: Desmond Cheong Zhi Xi Reported-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com Tested-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com Acked-by: Anton Altaparmakov Cc: Shuah Khan Cc: Greg Kroah-Hartman Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ntfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -477,7 +477,7 @@ err_corrupt_attr: } 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? */