Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4534326pxb; Sun, 14 Feb 2021 14:17:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzscnAYR1J9J35UFbRvC4lZIYVcLO6+ECwytGP9w8Nebt0L7Nbq1W/pHZkgOvmlWJ1QIUkq X-Received: by 2002:a17:906:17da:: with SMTP id u26mr13152093eje.281.1613341037491; Sun, 14 Feb 2021 14:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613341037; cv=none; d=google.com; s=arc-20160816; b=bT6TpWm1ij5eveZiLuPGxTUZp4VRmF9DuuJajNw6DN5eoQ3dG7aygf5KcstAfpWVBx jq2bQGI3ykC+bj1W+Y9H0DQCdntf9v7cMu6vIfNU/EeGORLpeb0HGm3xw3Uivy8RA1ld 6qT1C4pjTXiU8d0gBTHweTh/M0E/OUu3EaVs52mbQIl1tpYvX6FAJMYSUdW+I+d2fZMI CzW8Y9BEBplG73h0GQbvXNmSBCLAmi3Z0SROVWshpruIlxRa6WfkGxYaUs6Lcd7UPqyF vwwp/IHWbrxxOTUDcZ60Zs/rxdpTRvKVQGh4hwq/WSgzgcG6KsfMcqBz6DrHEj02o+C+ rOFw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=qdLNJb3inSse6CSVYJiB22jHj3yvabyJ9VxlXaI7xTQ=; b=uDOns0L+Q65QmrUe+S0Cr3d78byHgadzYtV/BojzDfv95MB8FKV8toZuKaU96OCQsR u6Eh6/mtHUWiB9rQznGjjeJmp3XfuCVG35V99eIJfrxQ2ULOGtJPs2TgnpUW8wG3vESm 08rjsFKlliiQfzwE9RnPlu8Z0ys8PvdUwvU0jw0jHTPvBZ6dFy4P81PwlERFCmmmVU2J +ag6on9GMos9Sy6dGziy8+z1LgOg3tOYy3H1xEsI//nHF0fHnz8k17APymm0258jRprz fAfjERicJN3/z0BMEl9hNvCW0kjofF6s2HKt05mDo5Xk0ptQz4RlyLfWJQnKtU1B4mxY h4Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=guPjJGqI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si10903162ejb.694.2021.02.14.14.16.53; Sun, 14 Feb 2021 14:17:17 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=guPjJGqI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbhBNWOf (ORCPT + 99 others); Sun, 14 Feb 2021 17:14:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhBNWOd (ORCPT ); Sun, 14 Feb 2021 17:14:33 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70042C061574 for ; Sun, 14 Feb 2021 14:13:53 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id z11so7427885lfb.9 for ; Sun, 14 Feb 2021 14:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qdLNJb3inSse6CSVYJiB22jHj3yvabyJ9VxlXaI7xTQ=; b=guPjJGqIqAsDmLr2n3cSflzbvX445lMiq+X/IMg/6mKjAbKsI/nKAYs2FkyT+px5tH Jwwgls8hS2qcCa4Znb0cgs8msdI4QDpZsUqgtKpCcPCm4OlZ2A+BvpKDSOr1ESRle20E vQrUcWdRddGx+FpCGMibLLGtrKa4UUZAMkayDTw56mcAQYiunZQjuiYl4vdAoRZP1qTb D56fJudTDwcke05ClTpG+l2vmeSYDshTNrRjqhHHttV3YO24OJNV0yio5h7QPyZ3gqt5 ia47sBlxwkNqwQ6b4XNt2RLM+eeTz3GgVKfhuGPhNd243Gsj8PC3zL11MEjYqVuLVXlU onOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qdLNJb3inSse6CSVYJiB22jHj3yvabyJ9VxlXaI7xTQ=; b=etw4QNtxi3kRwOuN6RTUrD/ipQIBJ+6AO8mrX3EPrnad0peluS2Zdwd/MO3wNlM1NG FbQbUMXjY+NB0lMf1Aroc9SVUQHMKcelic/QO3s5xMIMIWl90DRrpLgb4X+t0DPMnfP4 cCE8dip7s2Gmj+P+BbxHQIrHP/Dx+7fopwiJtQtRGXuBUltaoHI98aWg9ss8KgEfY9g9 qxfudewohSBPL4LN7wmO6zo8N17c1oQHG+XSYbACNa1fR+ifAFLAIL5r4AoI28ZENhMk fzavYDT5o0dEtq+T/DRM+IHqWfMAF2Gheggr4FlqYY03+ozYegbVrYhJqr/b4dkmsRfN rJVQ== X-Gm-Message-State: AOAM531DrB4VDX2BHPdVyAkJomeE7+QyMuzovJed1SZA7Ephf7Ikf6qp joM66ZWYNor1+lAEqhl+XWZVUz34E/mchbRBMoY= X-Received: by 2002:a05:6512:234d:: with SMTP id p13mr6933065lfu.87.1613340831866; Sun, 14 Feb 2021 14:13:51 -0800 (PST) Received: from localhost.localdomain (104.36.148.139.aurocloud.com. [104.36.148.139]) by smtp.gmail.com with ESMTPSA id i18sm2539271lfe.177.2021.02.14.14.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 14:13:51 -0800 (PST) From: Rustam Kovhaev To: anton@tuxera.com, linux-ntfs-dev@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Rustam Kovhaev Subject: [PATCH] ntfs: move check for valid resident attribute offset and length Date: Sun, 14 Feb 2021 14:12:47 -0800 Message-Id: <20210214221247.621431-1-rkovhaev@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org we should check for valid resident atribute offset and length before loading STANDARD_INFORMATION attribute in ntfs_read_locked_inode() let's make that check a bit earlier in the same function to avoid use-after-free bug Reported-and-tested-by: syzbot+c584225dabdea2f71969@syzkaller.appspotmail.com Signed-off-by: Rustam Kovhaev Link: https://syzkaller.appspot.com/bug?extid=c584225dabdea2f71969 --- fs/ntfs/inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index f7e4cbc26eaf..70745aea5106 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -629,6 +629,13 @@ static int ntfs_read_locked_inode(struct inode *vi) } a = ctx->attr; /* Get the standard information attribute value. */ + if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset) + + le32_to_cpu( + a->data.resident.value_length) > + (u8 *)ctx->mrec + vol->mft_record_size) { + ntfs_error(vi->i_sb, "Corrupt attribute list in inode."); + goto unm_err_out; + } si = (STANDARD_INFORMATION*)((u8*)a + le16_to_cpu(a->data.resident.value_offset)); @@ -731,14 +738,6 @@ static int ntfs_read_locked_inode(struct inode *vi) goto unm_err_out; } } else /* if (!a->non_resident) */ { - if ((u8*)a + le16_to_cpu(a->data.resident.value_offset) - + le32_to_cpu( - a->data.resident.value_length) > - (u8*)ctx->mrec + vol->mft_record_size) { - ntfs_error(vi->i_sb, "Corrupt attribute list " - "in inode."); - goto unm_err_out; - } /* Now copy the attribute list. */ memcpy(ni->attr_list, (u8*)a + le16_to_cpu( a->data.resident.value_offset), -- 2.30.0