Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3761404pxv; Mon, 19 Jul 2021 08:09:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVDwnnU1qYJSVaQCb+mguMRTX5q1WEr8BCcYA4R7L4G1RkaHFcT6wM4ktKfxjcZl1Msyb+ X-Received: by 2002:a92:d8d1:: with SMTP id l17mr17004767ilo.187.1626707386585; Mon, 19 Jul 2021 08:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707386; cv=none; d=google.com; s=arc-20160816; b=GFr0XuFihImJ62+HOPhp+UWQpByBa4VgeYuaMllHQy2IQTysSwuFUof5oX03VOMRQf giv0lHHQaAepKNV2VHxzGnJLhDmI/szCf0McupVTr9S0cCmyvOQ55tb4dkXj9CQtCx+v 63BQiwdgy4Q54h1h40NkdSV9uQXW6Kb4Ntn5S8tnJg8QT+3usYf5TsU4uUxzmwecLQbd EIweKKYkX8m9unHurGi+LghY14A0BpN9ESVR74cLZqvLOGctiO9OmNh7ZcL9rAT5WFow uUeQx4iMLTGueLA1wCvhEpKQXWW1gfy8Hin647oX/BoJPLrxhaRPEVmKqcO5tNz3JUh+ GB2g== 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=UsMIt5+Li17i76GyBBmaVb0TDqp+9bYAert3DkUwq2k=; b=iYTJyJbukdFU7S1V2R26FDBwn5Ofp4sg53g6vYrdiQfxfxRzZ5uj1jS5AyuOkwq4Vy c/gobB05lJfP9z9YOycRe9XSon3oScL7+kwzsqwI7O+f7zEpl2cWIKeeUSalM+DP/ybz vvvds/Szy5QhKp3uvQYPh/rq0AXgsTOJtIB1jmjwAb+tTrf5r8YM74wvL5Pkk2fY4LH8 SkA39s7Jn+rdI/243oACOdvhQpRnrion5hKQPiqKOfmyNba8V3uM/XyPJ85WxG4drMWC 7RCfNmxX8TqKXGiInBidMUUAoB4kduiGzmkwyTkUvCEThjvJrBO9gnKW8g5l+FH6iK7Z daTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pI9xyqFJ; 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 u4si10061583jak.4.2021.07.19.08.09.34; Mon, 19 Jul 2021 08:09:46 -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=pI9xyqFJ; 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 S243779AbhGSO1R (ORCPT + 99 others); Mon, 19 Jul 2021 10:27:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244095AbhGSOYs (ORCPT ); Mon, 19 Jul 2021 10:24:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 150F9611CE; Mon, 19 Jul 2021 15:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707104; bh=XKIdcRFmU5GuMtfXcljpIi+SkH8MyrVAUkuEs5VReRU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pI9xyqFJ9qHKaQetQDcUGo58b20Xza902F/4x6OKh5j4TFKNXv5+OC8xIh3pyRxP8 KPQxeycSXRu8knw+q/rOUsZO8btp99tP9C4KTGc1OV3yAdgg1R7Kktp5Pi8FoiFrVP N7OGwdjBiLfMKRfHbY9m4hBe1j7PqQ8oNIm8CYE4= 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 4.9 007/245] ntfs: fix validity check for file name attribute Date: Mon, 19 Jul 2021 16:49:09 +0200 Message-Id: <20210719144940.623198277@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@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 @@ -502,7 +502,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? */