From patchwork Mon Jul 3 07:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp353105vqx; Mon, 3 Jul 2023 00:53:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4inj0/ZmDtTAknPx9Cp0mYEccog6mBKEP8KqQbJEo+R9XMQ/ZOG2jGkEa1+0mr/vsoaB2K X-Received: by 2002:a05:6a20:1446:b0:111:a0e5:d2b7 with SMTP id a6-20020a056a20144600b00111a0e5d2b7mr14386472pzi.4.1688370837404; Mon, 03 Jul 2023 00:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688370837; cv=none; d=google.com; s=arc-20160816; b=xooYDqHlLiVDDFEXHO4nnHU1U7yxJJYwAoTEPQrbAULU+iO8CeizIhd7xDLoPwmTGa 2m7VV2z+ptHHKHHBEloXaDinqGKlqErnHxjiXi38sKNrRnGpGdLuzIzvI4NI7RnWueYC RfwhUzxFIzDvhOtaBtrevXZZ55qqrwwUS42nq7DN9pOI3bSMbv5aj3hN+gL6AiOxFbA9 PwddUbLdACuLne0bGgZN+WFeALZxX0cRYL+Y8ejNDEBFI5A3F6U1FjXNAKf44/JPV0oc WFYvKlAh+p29QCSGEw5sX4tEJKby/D4OhhIP8vkB1L3Q6/b4WzHBvHckgAlORYgJWy9g TsHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=Rx//LO9/7IMTU2TX9c0DIpKI/VjGm4z0Maj34lCnuA8=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=FOlobfs790+BoBq/QcLIPdk9hE6xYebB6a2mLqcTEt/fjj/rq3YZ3y9lRht98F8QOn V4A8XM9c7UNF8TRNcfFofKzus1jKrRlgWgxR6JEEroz6QZFiyHKlol/ydVvVVCX7F3ha luJPCwsj/ML1R5tqUjZUq3kQh8fUOSFLpNCjIWrEUv/dxmZ3wIcvkwtaNNSdE1JP3LlJ 2VJH63LG4I2P9F9duESOnbg17Sr2B9221B7nGI3FAHiajHOx/KnLNf6dpI4NAOfC1YV4 6/uR426auphO79SV9BE2BtgljyjQb7OfEAUIIguVpi4kHD4R7+yadS6F+QSF2FugEAeo KxEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mu+4Zi+t; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mbEfFe+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q8-20020a056a00088800b00681c3725a98si9492781pfj.82.2023.07.03.00.53.41; Mon, 03 Jul 2023 00:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mu+4Zi+t; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mbEfFe+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbjGCHcn (ORCPT + 99 others); Mon, 3 Jul 2023 03:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjGCHcl (ORCPT ); Mon, 3 Jul 2023 03:32:41 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7603CC; Mon, 3 Jul 2023 00:32:40 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 6740A1D34; Mon, 3 Jul 2023 07:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368769; bh=Rx//LO9/7IMTU2TX9c0DIpKI/VjGm4z0Maj34lCnuA8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mu+4Zi+tLFsNMkcxYwGJASldvxkMTPZFVITANt9PQgmJTIhNILUfanN8HReP5EGc5 xOzSWVLVzvh1CrbVPqqkTlw4n773/xN7s9TfM/EgnivaCCaitQa9SfuU+V/0/3DBz2 dDW1mRxHVXGxntNaJNTgR3OOLHnLFHs2erVFyFrA= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id D2AF71D1E; Mon, 3 Jul 2023 07:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369080; bh=Rx//LO9/7IMTU2TX9c0DIpKI/VjGm4z0Maj34lCnuA8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mbEfFe+uruU4DDxz9aMUbl86vfw5tJv1u7XTjIXN0qGP4zWp5U6A3fp4GDW60Dn7J UGp9F/YD7nbSA6VuaVUG+ZYaiHAKVGP8dP0FW4Br07t8eQbXVIYmXOg5fktOTnf6Yf iHxMePOqIco19Sq1QD1Fk18NmNFsNhLx4EcS2G0k= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:24:40 +0300 Message-ID: <379d007b-63d1-ab12-57aa-0ceee3d539a0@paragon-software.com> Date: Mon, 3 Jul 2023 11:24:39 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 1/8] fs/ntfs3: Add ckeck in ni_update_parent() Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770385139126880818?= X-GMAIL-MSGID: =?utf-8?q?1770385139126880818?= Check simple case when parent inode equals current inode. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/frecord.c | 6 ++++++  1 file changed, 6 insertions(+)          if (IS_ERR(dir)) { diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 16bd9faa2d28..8f34d6472ddb 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -3208,6 +3208,12 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,          if (!fname || !memcmp(&fname->dup, dup, sizeof(fname->dup)))              continue; +        /* Check simple case when parent inode equals current inode. */ +        if (ino_get(&fname->home) == ni->vfs_inode.i_ino) { +            ntfs_set_state(sbi, NTFS_DIRTY_ERROR); +            continue; +        } +          /* ntfs_iget5 may sleep. */          dir = ntfs_iget5(sb, &fname->home, NULL); From patchwork Mon Jul 3 07:25:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp345934vqx; Mon, 3 Jul 2023 00:33:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzfOSrXwjluqiCMX6up0gRQwTZ2jA3IWMjNx08aGWdj5kabmNnyT8f9SQEbO8mwKqkC+Y8 X-Received: by 2002:a17:903:786:b0:1b3:ec39:f42c with SMTP id kn6-20020a170903078600b001b3ec39f42cmr10076592plb.5.1688369616575; Mon, 03 Jul 2023 00:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688369616; cv=none; d=google.com; s=arc-20160816; b=qC3A/bfSlbAeJNIRkUMQEScVaTkXzMA8OWNg9RR+1WWrZMTKcdoblwWsPbdyLNsVxI ug8+Ff9yJCNXJh7hX8T3LZhbczyIKb5DP8U2vlQx6IHKPhZKGqwotRtVwd/k/qhq3KpS vuxrgC9l05wp13quVSeZLG946lVKc9TmmOV0jCiEBhI+r8pkS0KUX+bKo9CUlaqqDbJV MWJZttrd/EUkcvSENAuAc1B7VfJB7mOlcDwUtk6AOm1voSXrAJCZWQWZ1Wv8odvbn0rR 3ai4DJNdeSwuPS+ALt8Mf/8ol3/fs+r+d5g1p/VR1TtuZ0zMcTyeNJsVU9XCRozcQCDI eBow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=HNQF4HBbkbbtfs/+y+hwwE6jqL+QQ9MoDuKoaujlRVA=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=EVZBllE5x+EcmJFZ1A4wWhUvU4CtPhD3aBVHd+qUBwEQ1D+hk+DhfT/L6QccdLiFh/ J4pjDgjrRPaiih5xP8JAJox3ZpsO537uoWBuzJlCYFCAKGPIkcG0jXXgVweyjTrPvxay dbnoScJkztmOF6+Vtlon5NPw2NBHhXn2I5taAJuE9SSaizKxgRpeFM9Isf1N/cltQyh9 AU6d+ff8aSXAld+cOGs+rVhpOAdu8SmCLInjCqOqS96vR1bGXFjB0C1SgFQYU/S+B07p fQyhEtajg0/cLAjJBg1nK6N3WJmNbISKzCqUoGPCuzYR3bvEyVy6rFl2HQN4oznKdb+p uBlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=hOGcwcG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e17-20020a17090301d100b001b89bd6fd59si964804plh.215.2023.07.03.00.33.24; Mon, 03 Jul 2023 00:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=hOGcwcG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230351AbjGCHZU (ORCPT + 99 others); Mon, 3 Jul 2023 03:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbjGCHZQ (ORCPT ); Mon, 3 Jul 2023 03:25:16 -0400 X-Greylist: delayed 78 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 03 Jul 2023 00:25:11 PDT Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A192DE44; Mon, 3 Jul 2023 00:25:11 -0700 (PDT) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 4FC781D74; Mon, 3 Jul 2023 07:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368798; bh=HNQF4HBbkbbtfs/+y+hwwE6jqL+QQ9MoDuKoaujlRVA=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=hOGcwcG1jbJ4se1vlTg/W5WaRKGWc44Bq9SzAw5Jb9TxByG1vGa3Mr+Iwd5Ly5i1B VbZuU0TYKlIOIwqTe6c9wx+0Em4Ug+UbOJQCEOesR9KWgDJo1zr/d3WKzDBMyFI6WV BSWaDR92yG1LPRDrgP2xQTjvWGpnMaU/ea6jfyk0= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:25:09 +0300 Message-ID: <55b51679-e500-353c-d670-74e2f7697155@paragon-software.com> Date: Mon, 3 Jul 2023 11:25:08 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 2/8] fs/ntfs3: Write immediately updated ntfs state Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770383859162652043?= X-GMAIL-MSGID: =?utf-8?q?1770383859162652043?= Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fsntfs.c | 13 +++----------  1 file changed, 3 insertions(+), 10 deletions(-)  } diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 33afee0f5559..edb51dc12f65 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -983,18 +983,11 @@ int ntfs_set_state(struct ntfs_sb_info *sbi, enum NTFS_DIRTY_FLAGS dirty)      if (err)          return err; -    mark_inode_dirty(&ni->vfs_inode); +    mark_inode_dirty_sync(&ni->vfs_inode);      /* verify(!ntfs_update_mftmirr()); */ -    /* -     * If we used wait=1, sync_inode_metadata waits for the io for the -     * inode to finish. It hangs when media is removed. -     * So wait=0 is sent down to sync_inode_metadata -     * and filemap_fdatawrite is used for the data blocks. -     */ -    err = sync_inode_metadata(&ni->vfs_inode, 0); -    if (!err) -        err = filemap_fdatawrite(ni->vfs_inode.i_mapping); +    /* write mft record on disk. */ +    err = _ni_write_inode(&ni->vfs_inode, 1);      return err; From patchwork Mon Jul 3 07:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp347914vqx; Mon, 3 Jul 2023 00:38:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7g0sQBuEd6edxby+Fg3neM+7tt4fCNVmMqLC9te1U6wY0MSk8osbptIpCAWndYcFE7kUD6 X-Received: by 2002:a05:6a20:1446:b0:111:a0e5:d2b7 with SMTP id a6-20020a056a20144600b00111a0e5d2b7mr14356007pzi.4.1688369933261; Mon, 03 Jul 2023 00:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688369933; cv=none; d=google.com; s=arc-20160816; b=Eyzof54B1kEKAOpWfuzaNgmPXnIcr4dJwm60vMnt2mkx8tlyfLHu5tvltz4zin0KX0 QIi3a3yM4WdH+ZsPKK5ec5gjAH11AitTkS/YW5PvEwcFvc8T/kxdvb3UaNpSjmBsm6AT oZ/I7tIm91KA2nij5oYIx9KBZfwungHuWqyzgM7sWRSMo1y+/u2XW4+mLabhL6JZDzHX MhvV8M8uuHa1buluwZAmub91oc9A45VRewR9IyZFrowrzvPQOWXzI+U03XqF05k56u9D w5GYAR6huuEBFX3JgGuUI2/W/YjLm/6MJ856hY7rawGp/rfqAhr7+mEj+GnfhvDGin/e K4vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=idQe/8I4/xtf47MoCwShCKiDMRqvp0LjVacaYr6AkWU=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=pIwTTI+woRuEOsdIabf2dTBUADPuhVY9kMVSnvHrPJH2+aeb/K/OgyOVcV3cADPfRy AvjlERhe6WDzVgGLYPOcn3QqH6Rf2pi/wRoVj8pgYbz/nA4Y0RcMltHQQ/yS2BwHBbuQ 36mRNdCAj3BXU7sgZx424rQZi63SmKfNx7kSDYvaYWNPUCwK7zxK2NH+/lzOBeINayOu 18Zb22hg1Cqi3yZ4DcfprFj5MDrqEDbaE2ijVn1OLU2cOy2C1wRPyVy4CwYq7zWmByh8 l9jHBjcLDbICDaEbHJFgBkezsI8UyJYsoWLsUHd6gFyBSLvhescg2rU8xWE4KSYh+2UG HDCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=jqwwrq8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a1709027c0c00b001b55070e154si14776649pll.96.2023.07.03.00.38.40; Mon, 03 Jul 2023 00:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=jqwwrq8B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbjGCHZ4 (ORCPT + 99 others); Mon, 3 Jul 2023 03:25:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbjGCHZs (ORCPT ); Mon, 3 Jul 2023 03:25:48 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5FEAE6C; Mon, 3 Jul 2023 00:25:34 -0700 (PDT) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 1F2C31D74; Mon, 3 Jul 2023 07:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368821; bh=idQe/8I4/xtf47MoCwShCKiDMRqvp0LjVacaYr6AkWU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=jqwwrq8B8R664q9ffRJjmOoR2X8CkRNU4rlXglrlwAsRvgRunVJuYY9Nzd/Serb3x wZNXxN6TabamoZsxq4gvnA44ipNC5KLs/YzKRjXVD6bnZ+qF++zZ+TN646VFIW2Hp8 g+7ng2XewnogU8vU+K6qNydqFDKkhcl9brgaeiik= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:25:32 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:25:31 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 3/8] fs/ntfs3: Minor code refactoring and formatting Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770384190860199738?= X-GMAIL-MSGID: =?utf-8?q?1770384190860199738?= Trim spaces and clang-format. Add comment for mi_enum_attr. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/namei.c  | 2 +-  fs/ntfs3/ntfs.h   | 2 +-  fs/ntfs3/record.c | 6 ++++++  fs/ntfs3/super.c  | 3 +--  fs/ntfs3/xattr.c  | 3 ++-  5 files changed, 11 insertions(+), 5 deletions(-)          ea_size = unpacked_ea_size(ea); diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 70f8c859e0ad..dd38dbf30add 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -376,7 +376,7 @@ static int ntfs_atomic_open(struct inode *dir, struct dentry *dentry,  #ifdef CONFIG_NTFS3_FS_POSIX_ACL      if (IS_POSIXACL(dir)) { -        /* +        /*           * Load in cache current acl to avoid ni_lock(dir):           * ntfs_create_inode -> ntfs_init_acl -> posix_acl_create ->           * ntfs_get_acl -> ntfs_get_acl_ex -> ni_lock diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 98b76d1b09e7..86aecbb01a92 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -847,7 +847,7 @@ struct OBJECT_ID {      // Birth Volume Id is the Object Id of the Volume on.      // which the Object Id was allocated. It never changes.      struct GUID BirthVolumeId; //0x10: - +      // Birth Object Id is the first Object Id that was      // ever assigned to this MFT Record. I.e. If the Object Id      // is changed for some reason, this field will reflect the diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index c12ebffc94da..cae939cb42cf 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -189,6 +189,12 @@ int mi_read(struct mft_inode *mi, bool is_mft)      return err;  } +/* + * mi_enum_attr - start/continue attributes enumeration in record. + * + * NOTE: mi->mrec - memory of size sbi->record_size + * here we sure that mi->mrec->total == sbi->record_size (see mi_read) + */  struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)  {      const struct MFT_REC *rec = mi->mrec; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 1a02072b6b0e..d24f2da36bb2 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -488,7 +488,6 @@ static ssize_t ntfs3_label_write(struct file *file, const char __user *buffer,  {      int err;      struct super_block *sb = pde_data(file_inode(file)); -    struct ntfs_sb_info *sbi = sb->s_fs_info;      ssize_t ret = count;      u8 *label = kmalloc(count, GFP_NOFS); @@ -502,7 +501,7 @@ static ssize_t ntfs3_label_write(struct file *file, const char __user *buffer,      while (ret > 0 && label[ret - 1] == '\n')          ret -= 1; -    err = ntfs_set_label(sbi, label, ret); +    err = ntfs_set_label(sb->s_fs_info, label, ret);      if (err < 0) {          ntfs_err(sb, "failed (%d) to write label", err); diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 1a518550c317..c59d6f5a725a 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -211,7 +211,8 @@ static ssize_t ntfs_list_ea(struct ntfs_inode *ni, char *buffer,      size = le32_to_cpu(info->size);      /* Enumerate all xattrs. */ -    for (ret = 0, off = 0; off + sizeof(struct EA_FULL) < size; off += ea_size) { +    ret = 0; +    for (off = 0; off + sizeof(struct EA_FULL) < size; off += ea_size) {          ea = Add2Ptr(ea_all, off); From patchwork Mon Jul 3 07:26:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp348030vqx; Mon, 3 Jul 2023 00:39:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlF4kxQB0oGMd1AFzdAyQ0Xly1iZTEKod7LBbpX8mjLOlXDg7xEVx0xS55PxBFJhfDldqBf9 X-Received: by 2002:a17:902:e294:b0:1af:adc2:ab5b with SMTP id o20-20020a170902e29400b001afadc2ab5bmr10451612plc.0.1688369950256; Mon, 03 Jul 2023 00:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688369950; cv=none; d=google.com; s=arc-20160816; b=Tf6EYeVUbKxyK9NiXIBI8MjqZUGuy0ahFMC/HLEOySkIO/Ckl/Zpr7A9WhCZMJlG6t KCLooTCyMKDqewS2EKlvPzEeCtPFBGz37E0Hxw5TCy56QouYk2RCAtjGxEoZ1eb0tjaY wMIgaRB1oDuF2yUD/bTluWEGEUr2KeSfKoVMPCitMmSWePHrUmS9sTxc78SR3LU7sC5F 4njae0Y3qwQrFWROWD7fczi+L5eM7FfN7xaEU1KxX2RTEc+BcyxD80V246v3+EbJ0PCH muku9SoX9rWKJyQmUODN8wMsN7R0Vr7sEGD+APRjSE41Jvr2xoxSuqqhxbvxGfYbwcZ1 tk6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=+eBsKb2HTBRR8iMsfkWgMdZnxlIJ4gxnl7NXRmJUV8k=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=l4WHpqwiltHJ4RswLhRzIP3o1vfne/f9DOcqfkLyKGTMXHSYrMLY0+680w7IHWYlyL 0YdvA0KcAesJF7rJiSU/QiI8S8na1McA1JeVAA7yOcSBsIAblL9cZBP4zDqlFQAhJt4L d9FK3HsYy3BQMOa64dzt4GLhNf/vRIBry/qqZPhEG2Dy8lg6OyDkhHNL3LAY1295V5/+ TfRmY8l03pYavRmX28bCD09FdZ8Yg/ArJ5O+w5CtseGMFu26lOLcCreaTA+GT+83/G1V ++N2RRsjmTb8Fs5Ri19CRWx5r4PfqniSV6dahMjRDz6RJ0WGVLgs11BTRYPXlmGF0prC 4LQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=S0F7IwFq; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZBp5rhzn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a170902b40300b001ae5fe35b6esi17041877plr.261.2023.07.03.00.38.54; Mon, 03 Jul 2023 00:39:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=S0F7IwFq; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZBp5rhzn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbjGCH0S (ORCPT + 99 others); Mon, 3 Jul 2023 03:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjGCH0Q (ORCPT ); Mon, 3 Jul 2023 03:26:16 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5638E55; Mon, 3 Jul 2023 00:26:08 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 27D1D1D74; Mon, 3 Jul 2023 07:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368855; bh=+eBsKb2HTBRR8iMsfkWgMdZnxlIJ4gxnl7NXRmJUV8k=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=S0F7IwFq6c40h6gaEVdITZiroO+ZvZZ7+haTDwG7SUnO9xUWQul5u8vrjXJCUI2zF c49G0p4igW/1KdgwlwzRA0U6GP0EaxMmxiZ9YTB66g9k9NaCAfXn+0e3f4Ix0J/KH0 XJZlEw2GHdOfNcWFHxLLz3BxujT5lf8W2i2kU15k= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 970F41D1E; Mon, 3 Jul 2023 07:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369166; bh=+eBsKb2HTBRR8iMsfkWgMdZnxlIJ4gxnl7NXRmJUV8k=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ZBp5rhznk1XyJ0MlCxs6qu+hl7QD7YL6ibfUhcXAbi0M2+qxtzaQou6K/7emjY8m7 o7dCJJpvZa699JIbR2dGdDTUsfbeieG5EPhehEcBTthpzsqZDK1hmx77LtbSxWdkgp GpkZ3aiTrUf+R/FzV1q4EliIHaVDa2BpEuapv4Hk= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:26:06 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:26:05 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 4/8] fs/ntfs3: Don't allow to change label if volume is read-only Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770384209281432373?= X-GMAIL-MSGID: =?utf-8?q?1770384209281432373?= Signed-off-by: Konstantin Komarov ---  fs/ntfs3/super.c | 7 ++++++-  1 file changed, 6 insertions(+), 1 deletion(-)          return -ENOMEM; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index d24f2da36bb2..da739e509269 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -489,7 +489,12 @@ static ssize_t ntfs3_label_write(struct file *file, const char __user *buffer,      int err;      struct super_block *sb = pde_data(file_inode(file));      ssize_t ret = count; -    u8 *label = kmalloc(count, GFP_NOFS); +    u8 *label; + +    if (sb_rdonly(sb)) +        return -EROFS; + +    label = kmalloc(count, GFP_NOFS);      if (!label) From patchwork Mon Jul 3 07:26:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115210 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp353910vqx; Mon, 3 Jul 2023 00:56:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7z5he9l0PfNhov9H2YL3GjA5dLEKoj2mYVBjgvg3cH0gnvZdUYhiD8EuQrX9xhS084TdyP X-Received: by 2002:a05:6a21:339a:b0:121:b5af:acbc with SMTP id yy26-20020a056a21339a00b00121b5afacbcmr12586286pzb.3.1688370978202; Mon, 03 Jul 2023 00:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688370978; cv=none; d=google.com; s=arc-20160816; b=OnzhMxT6w33AHmZFiebHNkC9bnNIvrmy/6nB92QpfVwUR8aPrpFPlqYFGHXFJNZO44 GNTMI+OggfthCxam6VoN+6W8j8GnU46fLZt+1zVo8NUCNLCcw2COKDyfxjMRTo/e0RJI 7OWtaafDh80JTI1HXy+n+1HlKtW4Q2zmuxPyuoD4nSsDt0LHLDkGWSFvVcyN0Ebgk2Ld iytRzp6+Q+22JRezoYhxXC84Kub8y2NuGA/5OHJtioUDezXmjUl4YSO3Gx4g1ctenO9C OCkHynTmOQ4o/invKvP2wiuaLDfwdnwI2VWyMSmLphBSBaQV4nZZG0/VMiuoKHUzvADk H4jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=vlNC3aqT1PLyINaRjLgT5dt7keaunUkuSQDjNJ9mzS8=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=c5aVv/qXFetNDZjY0uKhk71bOGw7Lk1WAAE2p1EjZydOpCR4eBZiPi1epEkgi9koht hfLjCM2i02oVIxNtEXnm8zT0Bnfr5XaHtG04kZzrq9K/4Um+MKcDhKYHjHCJ3Fq7p20U KeY2cuLmD5EQRghvKdHTfSy+Yh6eZoFZorKH3r2guCgOfqMqO7pairpt1B7Mbf+oIYBd TiBFDMl0mnvfTsu6vNeGsktTAOqpGyZr9XbsFWRbxWn6nB2phsNZopElwesuSvH222mO CMiZ8Y6DGOajqB9q9k5A157Wxrxt2LLjXCyVfYIX5sZSp60y1rdMLWcAP726DJ1tA2LH tezQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=qF1ERGbX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a634c11000000b0055384255b9bsi16801327pga.24.2023.07.03.00.56.05; Mon, 03 Jul 2023 00:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=qF1ERGbX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjGCH0y (ORCPT + 99 others); Mon, 3 Jul 2023 03:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjGCH0t (ORCPT ); Mon, 3 Jul 2023 03:26:49 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756C9E7A; Mon, 3 Jul 2023 00:26:39 -0700 (PDT) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 134861D74; Mon, 3 Jul 2023 07:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368886; bh=vlNC3aqT1PLyINaRjLgT5dt7keaunUkuSQDjNJ9mzS8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=qF1ERGbXVCfRF81fRmeXF7le5tiNB5aw8lYBUUKRh7sxSiHitGOZ5U92gH6LVSV5N 7vVl257xtBbRv6qSnyHU5ND//ac6PFjXjLL1R3aWqyRXR8tpBn2J7V6FymwnVeVryC jlSEGvv5l4ExEpdPCuQwNhGcX53Q3gsA9XFZX2eI= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:26:37 +0300 Message-ID: <890222ac-1bd2-6817-7873-390801c5a172@paragon-software.com> Date: Mon, 3 Jul 2023 11:26:36 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 5/8] fs/ntfs3: Use kvmalloc instead of kmalloc(... __GFP_NOWARN) Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770385286933969654?= X-GMAIL-MSGID: =?utf-8?q?1770385286933969654?= Signed-off-by: Konstantin Komarov ---  fs/ntfs3/attrlist.c | 15 +++++++++++++--  fs/ntfs3/bitmap.c   |  3 ++-  fs/ntfs3/super.c    |  2 +-  3 files changed, 16 insertions(+), 4 deletions(-)          goto put_inode_out; diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c index 42631b31adf1..7c01735d1219 100644 --- a/fs/ntfs3/attrlist.c +++ b/fs/ntfs3/attrlist.c @@ -52,7 +52,8 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)      if (!attr->non_res) {          lsize = le32_to_cpu(attr->res.data_size); -        le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN); +        /* attr is resident: lsize < record_size (1K or 4K) */ +        le = kvmalloc(al_aligned(lsize), GFP_KERNEL);          if (!le) {              err = -ENOMEM;              goto out; @@ -80,7 +81,17 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)          if (err < 0)              goto out; -        le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN); +        /* attr is nonresident. +         * The worst case: +         * 1T (2^40) extremely fragmented file. +         * cluster = 4K (2^12) => 2^28 fragments +         * 2^9 fragments per one record => 2^19 records +         * 2^5 bytes of ATTR_LIST_ENTRY per one record => 2^24 bytes. +         * +         * the result is 16M bytes per attribute list. +         * Use kvmalloc to allocate in range [several Kbytes - dozen Mbytes] +         */ +        le = kvmalloc(al_aligned(lsize), GFP_KERNEL);          if (!le) {              err = -ENOMEM;              goto out; diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 107e808e06ea..d66055e30aff 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -659,7 +659,8 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)          wnd->bits_last = wbits;      wnd->free_bits = -        kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS | __GFP_NOWARN); +        kvmalloc_array(wnd->nwnd, sizeof(u16), GFP_KERNEL | __GFP_ZERO); +      if (!wnd->free_bits)          return -ENOMEM; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index da739e509269..0034952b9ccd 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1373,7 +1373,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      }      bytes = inode->i_size; -    sbi->def_table = t = kmalloc(bytes, GFP_NOFS | __GFP_NOWARN); +    sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL);      if (!t) {          err = -ENOMEM; From patchwork Mon Jul 3 07:27:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp352656vqx; Mon, 3 Jul 2023 00:52:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHErm6pE/4YgBoPlFoBuhUeVKN3npQrMIXP1Xladt1XLpHYimfi1dnWjeF0IAa6Xlnz94Um X-Received: by 2002:a05:6a00:8016:b0:677:3439:874a with SMTP id eg22-20020a056a00801600b006773439874amr11026939pfb.3.1688370737695; Mon, 03 Jul 2023 00:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688370737; cv=none; d=google.com; s=arc-20160816; b=iDlgqFvOgjmdEC7CHgQiDpYtr4I0QZtvXlYsRg8wRO3ur3TL0Qn/9iXU/2cV1D50Px 46aZJbccnpF+cYcLxH/wHc1GeqoPffb3CZczZS7rulwk1g4HVkKHTPyR8rDA/z61n44I b9Gv8RgHSXu7iV5cUSGPuFEeDPkzJF/geEaRPvq0jtK+ccDEGh43l496/Fn9RRGICels bwMyUU/9qBUGAtvn7nIkYpMTjFiQl2BAnKrw1jU5tsj6IjZ3fygmHQn0yTr1+TxGcDbY hO38O1vMKfEutRKCQ2FJv/1M/qNRG27S+nGjHA35w8zSff6uhfpWNWJQohGcxtzZvm13 CPbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=D5iKNYHdfTlYuVyZq7hZxLedK3pQqQ8YbD1w2/CiIkM=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=kQQC/EWJ60iPn/h7jlyFLmu69OnEpTRfMbKZ/N2Wrv7r/JDpaeoTEgGZE6PdCVdQwL KICISWZRnll2ejIlZc0M/9waHGvJ6PncBm5El5ol3HqQnZEIkb4K3IOM6GXtTmosGoHy xFSmbO9jPIwCKoewizJtAm/bt19I8i2x608qRpyVAnl0Opk3HILeyYNOOS6ONHiafJ3c aF1mRUHPm+i0C1nVIdaEM6c/EmBpgXBIiCJuJeQqLuzteq1Uc1IvskscsNXhztq5bdjY GxMAuv1pIztzOWwO+WezmaYNaMshfrw2189auIbKThbRS3gaNuYa0jc/MQRjZoHnYS8u VOxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=CI1shzoj; dkim=pass header.i=@paragon-software.com header.s=mail header.b="QLU2NYl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn13-20020a056a00340d00b00678e14c629bsi14201769pfb.401.2023.07.03.00.52.05; Mon, 03 Jul 2023 00:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=CI1shzoj; dkim=pass header.i=@paragon-software.com header.s=mail header.b="QLU2NYl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbjGCH1v (ORCPT + 99 others); Mon, 3 Jul 2023 03:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjGCH1t (ORCPT ); Mon, 3 Jul 2023 03:27:49 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FE02E73; Mon, 3 Jul 2023 00:27:24 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 701271D74; Mon, 3 Jul 2023 07:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368931; bh=D5iKNYHdfTlYuVyZq7hZxLedK3pQqQ8YbD1w2/CiIkM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=CI1shzojPy5vSQ43J+xYNHD1Gzp0EmNYBN5Mogs5S3EuABT2FjWh00R7QynsARaqy L7Nmq6ppKhjiM2BncRx78NR9lx2quEERAFxeRoJLHNXG0vHRzRFzpn1MxA6fpxxEmF Am2OoGIy/JyfpI/3JZUBFO6opPSLk7uzr8jti1/g= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id D85EF1D1E; Mon, 3 Jul 2023 07:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369242; bh=D5iKNYHdfTlYuVyZq7hZxLedK3pQqQ8YbD1w2/CiIkM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=QLU2NYl/jPH9ptdm9LSZC8zXlU5D+m3dcAntTbIaWBkv4YUEl+TZvLtAyrmqWMP0X 0hjnpbirOKPB6D/3tyOtJXQ1+pbGGrisCNWVvD1n6B8kiABkXs1gxVlFPbqPIB2IZE fPlsir8M7+6++8uLNS8rbBZrXuMMDSSB6h1J6jto= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:27:22 +0300 Message-ID: <18640b25-5018-ebf2-38d9-e750404cb66f@paragon-software.com> Date: Mon, 3 Jul 2023 11:27:21 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 6/8] fs/ntfs3: Add more attributes checks in mi_enum_attr() Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770385034956268439?= X-GMAIL-MSGID: =?utf-8?q?1770385034956268439?= Signed-off-by: Konstantin Komarov ---  fs/ntfs3/record.c | 68 ++++++++++++++++++++++++++++++++++++-----------  1 file changed, 52 insertions(+), 16 deletions(-)          u32 total = le32_to_cpu(rec->total); @@ -219,6 +220,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)          if (!is_rec_inuse(rec))              return NULL; +        prev_type = 0;          attr = Add2Ptr(rec, off);      } else {          /* Check if input attr inside record. */ @@ -232,11 +234,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)              return NULL;          } -        if (off + asize < off) { -            /* Overflow check. */ +        /* Overflow check. */ +        if (off + asize < off)              return NULL; -        } +        prev_type = le32_to_cpu(attr->type);          attr = Add2Ptr(attr, asize);          off += asize;      } @@ -256,7 +258,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)      /* 0x100 is last known attribute for now. */      t32 = le32_to_cpu(attr->type); -    if ((t32 & 0xf) || (t32 > 0x100)) +    if (!t32 || (t32 & 0xf) || (t32 > 0x100)) +        return NULL; + +    /* attributes in record must be ordered by type */ +    if (t32 < prev_type)          return NULL;      /* Check overflow and boundary. */ @@ -265,16 +271,15 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)      /* Check size of attribute. */      if (!attr->non_res) { +        /* Check resident fields. */          if (asize < SIZEOF_RESIDENT)              return NULL;          t16 = le16_to_cpu(attr->res.data_off); -          if (t16 > asize)              return NULL; -        t32 = le32_to_cpu(attr->res.data_size); -        if (t16 + t32 > asize) +        if (t16 + le32_to_cpu(attr->res.data_size) > asize)              return NULL;          t32 = sizeof(short) * attr->name_len; @@ -284,21 +289,52 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)          return attr;      } -    /* Check some nonresident fields. */ -    if (attr->name_len && -        le16_to_cpu(attr->name_off) + sizeof(short) * attr->name_len > -            le16_to_cpu(attr->nres.run_off)) { +    /* Check nonresident fields. */ +    if (attr->non_res != 1) +        return NULL; + +    t16 = le16_to_cpu(attr->nres.run_off); +    if (t16 > asize) +        return NULL; + +    t32 = sizeof(short) * attr->name_len; +    if (t32 && le16_to_cpu(attr->name_off) + t32 > t16) +        return NULL; + +    /* Check start/end vcn. */ +    if (le64_to_cpu(attr->nres.svcn) > le64_to_cpu(attr->nres.evcn) + 1) +        return NULL; + +    data_size = le64_to_cpu(attr->nres.data_size); +    if (le64_to_cpu(attr->nres.valid_size) > data_size)          return NULL; -    } -    if (attr->nres.svcn || !is_attr_ext(attr)) { +    alloc_size = le64_to_cpu(attr->nres.alloc_size); +    if (data_size > alloc_size) +        return NULL; + +    t32 = mi->sbi->cluster_mask; +    if (alloc_size & t32) +        return NULL; + +    if (!attr->nres.svcn && is_attr_ext(attr)) { +        /* First segment of sparse/compressed attribute */ +        if (asize + 8 < SIZEOF_NONRESIDENT_EX) +            return NULL; + +        tot_size = le64_to_cpu(attr->nres.total_size); +        if (tot_size & t32) +            return NULL; + +        if (tot_size > alloc_size) +            return NULL; +    } else {          if (asize + 8 < SIZEOF_NONRESIDENT)              return NULL;          if (attr->nres.c_unit)              return NULL; -    } else if (asize + 8 < SIZEOF_NONRESIDENT_EX) -        return NULL; +    }      return attr;  } diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index cae939cb42cf..53629b1f65e9 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -199,8 +199,9 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)  {      const struct MFT_REC *rec = mi->mrec;      u32 used = le32_to_cpu(rec->used); -    u32 t32, off, asize; +    u32 t32, off, asize, prev_type;      u16 t16; +    u64 data_size, alloc_size, tot_size;      if (!attr) { From patchwork Mon Jul 3 07:27:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp353844vqx; Mon, 3 Jul 2023 00:56:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGA/Kbx4gYAcceRD/PkPRQLn95jJTjz24pK728KinjNR5RFAnd6umVMqswRROVPQbe7LonY X-Received: by 2002:a17:902:c9c5:b0:1b8:50a9:6874 with SMTP id q5-20020a170902c9c500b001b850a96874mr9618721pld.5.1688370965782; Mon, 03 Jul 2023 00:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688370965; cv=none; d=google.com; s=arc-20160816; b=hv1rMy8M7VUbeWorVg16yaaqkJ2cpQ9yQctHTwo1cgRcASeQFHFwp1x19IZ0wxOo7/ CMyFBqtdL/ielCAZ0fM+uN9uv/0riM+U0zKJVQtk8AzjM6zkoxvADNVYaK22JEQ+zVhm VF+LiidPewZ50OZzPSQBOJroyzX02ZkCqar3ahKMn3y7P9u6UcA3bZT065bkkxa4eBQ3 JfQAu43iHoon9yZTOgrfhM6IXFg2mUjpSZy/EiQeiLYvpuFKUy9uPyKeg5KJTPj+Vuxk eVLEMDve0OVj3UdmdCNEOqifI6yMb9CvhnrM7Qi7T2GReJoJXvm1HsLFqM8Zk5CxIKBU NSdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=q5eMVDMl8OohS/5+a1OTXjwPDE7CVMtEf2hDSqPpYdc=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=OYIBzYOMoke1ei+BDipE7M0dCDxROtqASctUNgby0K9iep4k7FaKw83VZI+Mdeqtcs V5UrG/QYsG6iRWoNkKybKfWosFlF6wCyCFb4hGcAOIBra57mjtcCvY9HS7ixsEDP7WIz TKmj/0mCyhOajHQvOLX9FLoHC8jNg3nw6+NGT0GNsIWEk52C+P9rjDrNHl6hLBDyjcWK s9rEoDbDiffpQkX4ldR9vmpuuAOlnc08Oped4ejqvCoQCSWDoQNrJwJEpFgNLwk2T8tc cNvBOnbMzJa3L+sInd66O3QTJS11Z4GSxwlxUgi7e0TKuHWTsGNnsCW+GQYItKIN/Zcr HabA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=RjkVAo7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id im16-20020a170902bb1000b001b03bacdc9dsi5322107plb.343.2023.07.03.00.55.52; Mon, 03 Jul 2023 00:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=RjkVAo7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbjGCH2C (ORCPT + 99 others); Mon, 3 Jul 2023 03:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbjGCH17 (ORCPT ); Mon, 3 Jul 2023 03:27:59 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A58E58; Mon, 3 Jul 2023 00:27:55 -0700 (PDT) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 3066D1D21; Mon, 3 Jul 2023 07:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368962; bh=q5eMVDMl8OohS/5+a1OTXjwPDE7CVMtEf2hDSqPpYdc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=RjkVAo7NwjKBmWEMvIlJsB79izFMwGHGw2m5t2MLac2t2fLRc9GuLr0ri2b88NDIf hH8hwrRf88DIOVYe57oacRxXKLbO4OITZPNsbEmre3dkirQEhKAP3ewdj6gXk1mvGs 1W4Yk/9Wnnl1BzrR4wVnCieGQvtG1qTiiZLXRwIg= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:27:53 +0300 Message-ID: <23596b4e-1a38-d944-3bba-de7d528c7bf6@paragon-software.com> Date: Mon, 3 Jul 2023 11:27:52 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 7/8] fs/ntfs3: fix deadlock in mark_as_free_ex Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770385273690131416?= X-GMAIL-MSGID: =?utf-8?q?1770385273690131416?= Reported-by: syzbot+e94d98936a0ed08bde43@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fsntfs.c | 6 +++++-  1 file changed, 5 insertions(+), 1 deletion(-)          len = 0; @@ -2511,6 +2513,8 @@ void mark_as_free_ex(struct ntfs_sb_info *sbi, CLST lcn, CLST len, bool trim)  out:      up_write(&wnd->rw_lock); +    if (dirty) +        ntfs_set_state(sbi, NTFS_DIRTY_ERROR);  }  /* diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index edb51dc12f65..fbfe21dbb425 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -2454,10 +2454,12 @@ void mark_as_free_ex(struct ntfs_sb_info *sbi, CLST lcn, CLST len, bool trim)  {      CLST end, i, zone_len, zlen;      struct wnd_bitmap *wnd = &sbi->used.bitmap; +    bool dirty = false;      down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS);      if (!wnd_is_used(wnd, lcn, len)) { -        ntfs_set_state(sbi, NTFS_DIRTY_ERROR); +        /* mark volume as dirty out of wnd->rw_lock */ +        dirty = true;          end = lcn + len; From patchwork Mon Jul 3 07:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 115202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp346595vqx; Mon, 3 Jul 2023 00:35:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlELOSywQjFJimEaockjm12RPXBFaxYUgtf71tdrHzzGieaSRYvJvwvEr6e1bAa8VNk3LJgT X-Received: by 2002:a17:902:b20b:b0:1ae:4567:2737 with SMTP id t11-20020a170902b20b00b001ae45672737mr10129565plr.2.1688369714702; Mon, 03 Jul 2023 00:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688369714; cv=none; d=google.com; s=arc-20160816; b=hJmNyjg27iXVgCsiLYGD6TmUkRQtybVONrHTDdLs20KSHyLcRvMDzqKRN5eVKC3ddZ pCbx1SxDA/pYxZovKh5bjBI9xAlSxHYVkPS2r6lshiWCohsofuhhMC4o9tSW7RFkiJtS wkYjMoGoFFqAjbl1vuUYYOG9ixLFUQ8+rG3hftIFfga1v3X1nd5sGWoClYJOjJ8nylFY jXrQICMLBBETIlCKokV/7wjkxT0gVtqgzWktGWyIAUbrB7AW5dGdkK0+iTcWWVEoc9t2 g1skeMCTLWCUd4zxVaFUXg/S2DdRf4bvAD3MPKscFCjQa0Zss5j8Vw9rXN5jxxUyy4Tx XCrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=zSbz2rcKBXxPlxirBwRjMtqYwWRIZxW3itsjx+mpDUw=; fh=+YFVdCJq57+piIgB3kUO3LUIuYykw/jnC0zhAUs0Z14=; b=zkZsts9ubOzQf/T+WT9V31esxEKXV9pjPNDmEaPR/od6R5jbi58Z7hDlj5l33LAbWX IKFHZkAYxuAPYyDp73zwWfU3aQWop8lib1nN7WUrb1S7LRQc9yR/SYlaG8tqmQBlHyrf y/HA7PHiL5L54XxJwwUjyleTAUI6v3AH/Va4gu8j5BKSfJ//y4VlWA+WuvTClvGznhtO Z1zyFJdO5pUfI0mDDX2ryHtY3/5YMRijHV6EdRtrXUhjSauMfrVd/8Y42wATkAVhtBb1 b3lCe71atIDVECdg+eWICBhwzwkmRKgVGtPfG2RPhCZL2cNCzGDOAUOuixsTUU+s9BPU wbnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=DYoyooiN; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Lv+C1Xgn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a17090322cd00b001b86671b3f1si8132220plg.190.2023.07.03.00.35.01; Mon, 03 Jul 2023 00:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=DYoyooiN; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Lv+C1Xgn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbjGCH2f (ORCPT + 99 others); Mon, 3 Jul 2023 03:28:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjGCH2c (ORCPT ); Mon, 3 Jul 2023 03:28:32 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A74E55; Mon, 3 Jul 2023 00:28:28 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 94B1C1D21; Mon, 3 Jul 2023 07:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368995; bh=zSbz2rcKBXxPlxirBwRjMtqYwWRIZxW3itsjx+mpDUw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=DYoyooiNxquY396tRP4PveJSv97Iv0Ubc6k8OL0qQxFCA6XV8qkchtYOOoqDY9Ra+ t7yKwtRq3jIZDDqVANBULtAwLYwL/8uGar/18pHjMuBWJwDrWjiil/HB6HfJPIKS5G FLI/MYkMXFukxZXJvtk/m+4OJcOXuR370YsZz3Ag= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 0DE091D1E; Mon, 3 Jul 2023 07:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369307; bh=zSbz2rcKBXxPlxirBwRjMtqYwWRIZxW3itsjx+mpDUw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Lv+C1XgnNu8FamEESwPA7jrLynFkxB2x/2GVVnBNxkQPd5KO6vOyXEnbwYKGvxWMy QEdp3btymMdQO3l0HSsf1HdeQ+5KGzxNAQpPfAtjTFD79NrSQK+I+Y//QUVuoFJ8Hw v5bT3YcVraRNSndWCb5HxWWSgnKku9tLZ6TUgG3o= Received: from [192.168.211.138] (192.168.211.138) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 3 Jul 2023 10:28:26 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:28:25 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 8/8] fs/ntfs3: Fix shift-out-of-bounds in ntfs_fill_super Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.138] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770383961735826059?= X-GMAIL-MSGID: =?utf-8?q?1770383961735826059?= Reported-by: syzbot+478c1bf0e6bf4a8f3a04@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov ---  fs/ntfs3/ntfs_fs.h |  2 ++  fs/ntfs3/super.c   | 26 ++++++++++++++++++++------  2 files changed, 22 insertions(+), 6 deletions(-) @@ -924,9 +932,15 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          goto out;      } -    sbi->index_size = boot->index_size < 0 ? -                  1u << (-boot->index_size) : -                  (u32)boot->index_size << cluster_bits; +    if (boot->index_size >= 0) { +        sbi->index_size = (u32)boot->index_size << cluster_bits; +    } else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) { +        sbi->index_size = 1u << (-boot->index_size); +    } else { +        ntfs_err(sb, "%s: invalid index size %d.", hint, +             boot->index_size); +        goto out; +    }      /* Check index record size. */      if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 629403ede6e5..788567d71d93 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -42,9 +42,11 @@ enum utf16_endian;  #define MINUS_ONE_T            ((size_t)(-1))  /* Biggest MFT / smallest cluster */  #define MAXIMUM_BYTES_PER_MFT        4096 +#define MAXIMUM_SHIFT_BYTES_PER_MFT    12  #define NTFS_BLOCKS_PER_MFT_RECORD    (MAXIMUM_BYTES_PER_MFT / 512)  #define MAXIMUM_BYTES_PER_INDEX        4096 +#define MAXIMUM_SHIFT_BYTES_PER_INDEX    12  #define NTFS_BLOCKS_PER_INODE        (MAXIMUM_BYTES_PER_INDEX / 512)  /* NTFS specific error code when fixup failed. */ diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 0034952b9ccd..34ebfaa8fbab 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -905,9 +905,17 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          goto out;      } -    sbi->record_size = record_size = -        boot->record_size < 0 ? 1 << (-boot->record_size) : -                    (u32)boot->record_size << cluster_bits; +    if (boot->record_size >= 0) { +        record_size = (u32)boot->record_size << cluster_bits; +    } else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) { +        record_size = 1u << (-boot->record_size); +    } else { +        ntfs_err(sb, "%s: invalid record size %d.", hint, +             boot->record_size); +        goto out; +    } + +    sbi->record_size = record_size;      sbi->record_bits = blksize_bits(record_size);      sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes