Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2833628pxv; Mon, 12 Jul 2021 03:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqyuZmN2DUipks+BKW5kLLOyBwpJO0yjTqna+v/hBMm8UPTOBC+sJkn17c5xkOuQOiA3f5 X-Received: by 2002:a92:d307:: with SMTP id x7mr20058918ila.301.1626084321951; Mon, 12 Jul 2021 03:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084321; cv=none; d=google.com; s=arc-20160816; b=APCa9C9zTSalwZ3j2MIb92Kv1AZKQnPUUjx7YlCmFeiJGMnQu4U0H9v6jAT+8Zhw4o xhpYg5df3qdmIVaqf2XS9lvOZDZNG1YqdyKgYpDE/yn/t8sniVsWnA4tcQW+VgHyRZs7 eao2BFVsyoFEByuh0mlX2rAbnTU0HshKgXEajXYCjpK/5jE10CvT4Omsx05FIFxtrtIC VYy+M3PoOWvvymcB63BcbbKNLvKzFp9KolY9l/UbQY19XEyPjzDuNW2ekJhPnpXOCzy0 7A6czYlJN188nxZQa5JUo6yfl4p7IDA9NpevxnwIpaFYxzK4kcQlMxVPwIFD6ztt5yRy GUzw== 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=rqSGW8hTqpAfSADXXzwWZDDsXO00IwOyFT41hL7BuMWtv/rYbfhuV+m2mVUllP9Btz 8cyUgVysIzLsWofB8uL+yAo/6L4IL1reVbEhwxaxTcTqAPbFlxsWx9KWS4nibJbmc5Gk /ZtLUAYmGBu97FECgrCEfZLimT0guxZij3Q98LihAazNcjIsuFaNCJcLqzuvF3NliJYD e73z/TqHgfdto4p88NwJCeY6dOZ3Lbykmu0Y5VeOGmv2eyY/icD59skRJAu7bfF948zP NRF13XYsyuP+CuCIbtSS9lkIWcT7iEskwHoCB2ONgB6U49LedlzPWRVS87jEfMromdr+ 1nvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EEOJgvLt; 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 c24si18961725ioh.15.2021.07.12.03.05.10; Mon, 12 Jul 2021 03:05:21 -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=EEOJgvLt; 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 S1345203AbhGLHZF (ORCPT + 99 others); Mon, 12 Jul 2021 03:25:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:57200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239286AbhGLG6T (ORCPT ); Mon, 12 Jul 2021 02:58:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 518C561369; Mon, 12 Jul 2021 06:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072930; bh=HlmL8ZEFf25jX5xlbAq1x65up61lml7RPN6niPzCn00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EEOJgvLtLgbKFIPREvE4Hs4uTbOVEOt0qYhdrlsd/oERFfTmAHy5tNEw5wg/UOKgr REP1+BOzw8bU2eh7VLP6w3tNYqNTolF5jITYJzFMIqP65/dUM0AUAbBLT6grE4uE0O JmVubQFqZHsbB0HVVKhjb1vtANEAg6iXaw1Uj8R0= 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.12 032/700] ntfs: fix validity check for file name attribute Date: Mon, 12 Jul 2021 08:01:55 +0200 Message-Id: <20210712060929.166683245@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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? */