From patchwork Fri Oct 28 17:01:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp942141wru; Fri, 28 Oct 2022 10:05:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uXW0ClroJePXuSjUtaoMztAKwlZtNRA/xtJI9SqzwxgXOAb4JEQATDnbZh2x5MUGKOp0Q X-Received: by 2002:aa7:df16:0:b0:45b:f51f:ab73 with SMTP id c22-20020aa7df16000000b0045bf51fab73mr406918edy.366.1666976713255; Fri, 28 Oct 2022 10:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976713; cv=none; d=google.com; s=arc-20160816; b=XgOOuOKqP2bi756UKpi4BvyOQMwxU06pkMM89AxUCPSoSJFXL7Cd4yt6igxmcsdEiA eM//eI29S4vlsNZd10pGNf5tfP0TcWL9QBBUdQLmT2ffc8ncr5qkr/CzrOS3sgllZlUE nQVXx4pQhOtzr8kukErZ1JfVeF0QIF+hQZYs/BCTFBMeDmjqD8oFn8Elr7/gVl+szI2u IA19rnfkpDH7TS2yrSIj/fbGadU71o31ZvKx46uGVIo5MP7if2JpKjMQGDIu6NsgOWvx iXfVKNEMWP8xBmELegeFtmgiv8CZSZPWr+QiUWYbyjIm+3b1aL9c7TBr9W8vlw9gOlto 27WQ== 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=XLfhoLoajHMwxGkqzmutjSB0VcGNCexWxhovGxocDdI=; b=RJrk5ovJRR2u5ChNOLrKLDMzuqxZKruuG+N6o/lAe5O2E6l4gw/6xuBAtfiI6GU2+v MzpVqO4S3s6iDKSmewZ3xh058ORKaPcfmIomLRCNfzIZG/JsPdaKMwA9a+JynaCitjkg FkrXGL7dsAfpOj/rO1QxvpKL3QIhOmNNxamnKtQbIEC7pX8yZlwmP5w++zWPG5YM2cgg P2n6Jqs4vOj/z2V/8DntULVTK45VtMOEOOC8ggXDZvIiThO8Jt+3m9DQdhKQmeLrGs5O ifdAlZCo4W1021SC4SHFD+vk+CSrOhtWGmG77MFtUY1LyoZKv6NTIJLInThbvhJ9w2Xh ReJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=EW2if9qk; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mMpJm5c+; 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 gb36-20020a170907962400b007417040d1c5si4373357ejc.823.2022.10.28.10.04.38; Fri, 28 Oct 2022 10:05:13 -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=EW2if9qk; dkim=pass header.i=@paragon-software.com header.s=mail header.b=mMpJm5c+; 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 S231163AbiJ1RDr (ORCPT + 99 others); Fri, 28 Oct 2022 13:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbiJ1RD3 (ORCPT ); Fri, 28 Oct 2022 13:03:29 -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 BBDAE23081F; Fri, 28 Oct 2022 10:01:50 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 89070218D; Fri, 28 Oct 2022 16:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976349; bh=XLfhoLoajHMwxGkqzmutjSB0VcGNCexWxhovGxocDdI=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=EW2if9qksfM9ykb5vJ5T+0epiSG1fwqImLSQsTlJXDYcjNtWFffwQuMOhGlyFwRV8 VyTKUkkN4oTsHM//ZvfVw2hmDlygOYMwAJUFN7E4DLDOQSSqhrx3TGENdqSlXxyMJy 98HF+7e+WzRPqSSKloFrys6uA4apCN55EYB98MAM= 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 840D71D2B; Fri, 28 Oct 2022 17:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976508; bh=XLfhoLoajHMwxGkqzmutjSB0VcGNCexWxhovGxocDdI=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mMpJm5c+GkKRzjGX0HSF3iwKVFVVaYBhnyggovRXyg/bn0Q1waIULI89IHvQKUZfy c9dux2uNyDKICPgAHOZoz7hV3QHScHHxPG5wNixtPzXr7ThG5Gaf2e8qH6OKH0H46h QdPYy//F6Ip7e8rnGz801aOnM9hgNHAPKDdr/m9o= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:01:48 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:01:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 01/14] fs/ntfs3: Fixing work with sparse clusters Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747951774451148695?= X-GMAIL-MSGID: =?utf-8?q?1747951774451148695?= Simplify logic in ntfs_extend_initialized_size, ntfs_sparse_cluster and ntfs_fallocate. Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 45 ++++++++++++--------------------------------- fs/ntfs3/inode.c | 7 ++++++- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 4f2ffc7ef296..96ba3f5a8470 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -128,25 +128,9 @@ static int ntfs_extend_initialized_size(struct file *file, goto out; if (lcn == SPARSE_LCN) { - loff_t vbo = (loff_t)vcn << bits; - loff_t to = vbo + ((loff_t)clen << bits); - - if (to <= new_valid) { - ni->i_valid = to; - pos = to; - goto next; - } - - if (vbo < pos) { - pos = vbo; - } else { - to = (new_valid >> bits) << bits; - if (pos < to) { - ni->i_valid = to; - pos = to; - goto next; - } - } + pos = ((loff_t)clen + vcn) << bits; + ni->i_valid = pos; + goto next; } } @@ -279,8 +263,9 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn, { struct address_space *mapping = inode->i_mapping; struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info; - u64 vbo = (u64)vcn << sbi->cluster_bits; - u64 bytes = (u64)len << sbi->cluster_bits; + u8 cluster_bits = sbi->cluster_bits; + u64 vbo = (u64)vcn << cluster_bits; + u64 bytes = (u64)len << cluster_bits; u32 blocksize = 1 << inode->i_blkbits; pgoff_t idx0 = page0 ? page0->index : -1; loff_t vbo_clst = vbo & sbi->cluster_mask_inv; @@ -329,11 +314,10 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn, zero_user_segment(page, from, to); - if (!partial) { - if (!PageUptodate(page)) - SetPageUptodate(page); - set_page_dirty(page); - } + if (!partial) + SetPageUptodate(page); + flush_dcache_page(page); + set_page_dirty(page); if (idx != idx0) { unlock_page(page); @@ -341,7 +325,6 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn, } cond_resched(); } - mark_inode_dirty(inode); } /* @@ -588,11 +571,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) u32 frame_size; loff_t mask, vbo_a, end_a, tmp; - err = filemap_write_and_wait_range(mapping, vbo, end - 1); - if (err) - goto out; - - err = filemap_write_and_wait_range(mapping, end, LLONG_MAX); + err = filemap_write_and_wait_range(mapping, vbo, LLONG_MAX); if (err) goto out; @@ -693,7 +672,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) goto out; if (is_supported_holes) { - CLST vcn_v = ni->i_valid >> sbi->cluster_bits; + CLST vcn_v = bytes_to_cluster(sbi, ni->i_valid); CLST vcn = vbo >> sbi->cluster_bits; CLST cend = bytes_to_cluster(sbi, end); CLST lcn, clen; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index e9cf00d14733..f487d36c9b78 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -645,7 +645,12 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, bh->b_size = block_size; off = vbo & (PAGE_SIZE - 1); set_bh_page(bh, page, off); - ll_rw_block(REQ_OP_READ, 1, &bh); + + lock_buffer(bh); + bh->b_end_io = end_buffer_read_sync; + get_bh(bh); + submit_bh(REQ_OP_READ, bh); + wait_on_buffer(bh); if (!buffer_uptodate(bh)) { err = -EIO; From patchwork Fri Oct 28 17:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp942182wru; Fri, 28 Oct 2022 10:05:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44VIT9QTFYZevCtjW0d4ST12iptYkopdmHcvNfeWxZZneF69H6mNNnGoDYHquw35O/PCX2 X-Received: by 2002:a05:6402:35cb:b0:462:6545:5d99 with SMTP id z11-20020a05640235cb00b0046265455d99mr400747edc.51.1666976719082; Fri, 28 Oct 2022 10:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976719; cv=none; d=google.com; s=arc-20160816; b=Pyk3b/b7FIlX6NhNWQpG/H5W5ZsyuCzNP20BdZco1WpWPLxaJNsS158kFayCdKcE4s 2N428MQH60EMDiGFgdisbePDCdGuD5uE5HcbPO/u2LbBRFT6VKlIcVsumX5W9R1kcHUp t7noLBx5/JSfMhH7e8Y8D/iP1afuzbi7xmWljeijDGbiHK1mDeoJQw4U9r9VAv1DNSAb L/OneNCZONJ654WM2dhsLg2Np5O/xeQE9OHxqGED03wMgcEEyfQxpBgXFO5BUn7cEdCk 8M5b08ZYmXLyPib3Q7GFoFcZLvBy8pS5/6GE1o6yrbF7O0VrLsYr3kA5pCJgMgyrqEI9 F40w== 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=PM/O9yWZe1oGRmYJjiRyWgrKQ6k0lSNAUmnZBGKHpOU=; b=bGEPb/UDv8RWQS3NC9OTypSMlXL20fArRQUHNhXRinXGypKOEckILSBj5p30r7xooJ 0XZ76kauGA+qM9mb6FXwawqfB2+uWqwioEzbfFzhKwhYOJ4dPjuwqTf/d171hEoLHBSc BOnbZ2ilq9WpMFHFZtgGR8kQb8aYV4U35RTW6N3hxRPeSVfGVbJ1b3brdiEbxWOhtp2B 5HTXi8lA4PczEtcN6V3WY/RAcx+sWz4cAtbih8+lrUcY5GQGInM+uKAWZVZ44nkd9keX hLKa+GL6/FVrHVHPIzve+fZZZTgrwgVu+Pg4GhrfXOLK8iBeKrc+zntE2OUOXRptF1bK Ra3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=NadQuD2o; 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 p10-20020a50cd8a000000b004588172def1si5300816edi.410.2022.10.28.10.04.52; Fri, 28 Oct 2022 10:05:19 -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=NadQuD2o; 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 S230431AbiJ1RE0 (ORCPT + 99 others); Fri, 28 Oct 2022 13:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbiJ1RDz (ORCPT ); Fri, 28 Oct 2022 13:03:55 -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 15C6176751; Fri, 28 Oct 2022 10:02:22 -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 1B1B7218D; Fri, 28 Oct 2022 16:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976382; bh=PM/O9yWZe1oGRmYJjiRyWgrKQ6k0lSNAUmnZBGKHpOU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=NadQuD2oJM7haqauMfuv2DMoD8b2h88XZ/+DtM+Hx85CHRt8rL6qcbQCC3c3Ni4Dn 6NrcDiwPDCB9ZRamaY2t0hyX1p+iq/6vP4L0qT+gQREBqvRaLZy3v+yYO43rGIPcnS b+UVWOYdEWHNiIyWOSbc/kmhmIkDNhIcusC4OooA= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:02:20 +0300 Message-ID: <9aac3e4d-399d-335e-10dc-2742408720f7@paragon-software.com> Date: Fri, 28 Oct 2022 20:02:20 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 02/14] fs/ntfs3: Change new sparse cluster processing Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747951780190151514?= X-GMAIL-MSGID: =?utf-8?q?1747951780190151514?= Remove ntfs_sparse_cluster. Zero clusters in attr_allocate_clusters. Fixes xfstest generic/263 Signed-off-by: Konstantin Komarov --- fs/ntfs3/attrib.c | 176 +++++++++++++++++++++++++++++++-------------- fs/ntfs3/file.c | 146 +++++++++---------------------------- fs/ntfs3/frecord.c | 2 +- fs/ntfs3/index.c | 4 +- fs/ntfs3/inode.c | 12 ++-- fs/ntfs3/ntfs_fs.h | 7 +- 6 files changed, 166 insertions(+), 181 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 7c00656151fb..eda83a37a0c3 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -149,7 +149,7 @@ static int run_deallocate_ex(struct ntfs_sb_info *sbi, struct runs_tree *run, int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run, CLST vcn, CLST lcn, CLST len, CLST *pre_alloc, enum ALLOCATE_OPT opt, CLST *alen, const size_t fr, - CLST *new_lcn) + CLST *new_lcn, CLST *new_len) { int err; CLST flen, vcn0 = vcn, pre = pre_alloc ? *pre_alloc : 0; @@ -169,20 +169,36 @@ int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run, if (err) goto out; - if (new_lcn && vcn == vcn0) - *new_lcn = lcn; + if (vcn == vcn0) { + /* Return the first fragment. */ + if (new_lcn) + *new_lcn = lcn; + if (new_len) + *new_len = flen; + } /* Add new fragment into run storage. */ - if (!run_add_entry(run, vcn, lcn, flen, opt == ALLOCATE_MFT)) { + if (!run_add_entry(run, vcn, lcn, flen, opt & ALLOCATE_MFT)) { /* Undo last 'ntfs_look_for_free_space' */ mark_as_free_ex(sbi, lcn, len, false); err = -ENOMEM; goto out; } + if (opt & ALLOCATE_ZERO) { + u8 shift = sbi->cluster_bits - SECTOR_SHIFT; + + err = blkdev_issue_zeroout(sbi->sb->s_bdev, + (sector_t)lcn << shift, + (sector_t)flen << shift, + GFP_NOFS, 0); + if (err) + goto out; + } + vcn += flen; - if (flen >= len || opt == ALLOCATE_MFT || + if (flen >= len || (opt & ALLOCATE_MFT) || (fr && run->count - cnt >= fr)) { *alen = vcn - vcn0; return 0; @@ -257,7 +273,8 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr, const char *data = resident_data(attr); err = attr_allocate_clusters(sbi, run, 0, 0, len, NULL, - ALLOCATE_DEF, &alen, 0, NULL); + ALLOCATE_DEF, &alen, 0, NULL, + NULL); if (err) goto out1; @@ -552,13 +569,13 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, /* ~3 bytes per fragment. */ err = attr_allocate_clusters( sbi, run, vcn, lcn, to_allocate, &pre_alloc, - is_mft ? ALLOCATE_MFT : 0, &alen, + is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen, is_mft ? 0 : (sbi->record_size - le32_to_cpu(rec->used) + 8) / 3 + 1, - NULL); + NULL, NULL); if (err) goto out; } @@ -855,8 +872,19 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, return err; } +/* + * attr_data_get_block - Returns 'lcn' and 'len' for given 'vcn'. + * + * @new == NULL means just to get current mapping for 'vcn' + * @new != NULL means allocate real cluster if 'vcn' maps to hole + * @zero - zeroout new allocated clusters + * + * NOTE: + * - @new != NULL is called only for sparsed or compressed attributes. + * - new allocated clusters are zeroed via blkdev_issue_zeroout. + */ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, - CLST *len, bool *new) + CLST *len, bool *new, bool zero) { int err = 0; struct runs_tree *run = &ni->file.run; @@ -865,29 +893,27 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, struct ATTRIB *attr = NULL, *attr_b; struct ATTR_LIST_ENTRY *le, *le_b; struct mft_inode *mi, *mi_b; - CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end; + CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end, vcn0, alen; + unsigned fr; u64 total_size; - u32 clst_per_frame; - bool ok; if (new) *new = false; + /* Try to find in cache. */ down_read(&ni->file.run_lock); - ok = run_lookup_entry(run, vcn, lcn, len, NULL); + if (!run_lookup_entry(run, vcn, lcn, len, NULL)) + *len = 0; up_read(&ni->file.run_lock); - if (ok && (*lcn != SPARSE_LCN || !new)) { - /* Normal way. */ - return 0; + if (*len) { + if (*lcn != SPARSE_LCN || !new) + return 0; /* Fast normal way without allocation. */ + else if (clen > *len) + clen = *len; } - if (!clen) - clen = 1; - - if (ok && clen > *len) - clen = *len; - + /* No cluster in cache or we need to allocate cluster in hole. */ sbi = ni->mi.sbi; cluster_bits = sbi->cluster_bits; @@ -913,12 +939,6 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, goto out; } - clst_per_frame = 1u << attr_b->nres.c_unit; - to_alloc = (clen + clst_per_frame - 1) & ~(clst_per_frame - 1); - - if (vcn + to_alloc > asize) - to_alloc = asize - vcn; - svcn = le64_to_cpu(attr_b->nres.svcn); evcn1 = le64_to_cpu(attr_b->nres.evcn) + 1; @@ -937,36 +957,68 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, evcn1 = le64_to_cpu(attr->nres.evcn) + 1; } + /* Load in cache actual information. */ err = attr_load_runs(attr, ni, run, NULL); if (err) goto out; - if (!ok) { - ok = run_lookup_entry(run, vcn, lcn, len, NULL); - if (ok && (*lcn != SPARSE_LCN || !new)) { - /* Normal way. */ - err = 0; - goto ok; - } + if (!*len) { + if (run_lookup_entry(run, vcn, lcn, len, NULL)) { + if (*lcn != SPARSE_LCN || !new) + goto ok; /* Slow normal way without allocation. */ - if (!ok && !new) { - *len = 0; - err = 0; + if (clen > *len) + clen = *len; + } else if (!new) { + /* Here we may return -ENOENT. + * In any case caller gets zero length. */ goto ok; } - - if (ok && clen > *len) { - clen = *len; - to_alloc = (clen + clst_per_frame - 1) & - ~(clst_per_frame - 1); - } } if (!is_attr_ext(attr_b)) { + /* The code below only for sparsed or compressed attributes. */ err = -EINVAL; goto out; } + vcn0 = vcn; + to_alloc = clen; + fr = (sbi->record_size - le32_to_cpu(mi->mrec->used) + 8) / 3 + 1; + /* Allocate frame aligned clusters. + * ntfs.sys usually uses 16 clusters per frame for sparsed or compressed. + * ntfs3 uses 1 cluster per frame for new created sparsed files. */ + if (attr_b->nres.c_unit) { + CLST clst_per_frame = 1u << attr_b->nres.c_unit; + CLST cmask = ~(clst_per_frame - 1); + + /* Get frame aligned vcn and to_alloc. */ + vcn = vcn0 & cmask; + to_alloc = ((vcn0 + clen + clst_per_frame - 1) & cmask) - vcn; + if (fr < clst_per_frame) + fr = clst_per_frame; + zero = true; + + /* Check if 'vcn' and 'vcn0' in different attribute segments. */ + if (vcn < svcn || evcn1 <= vcn) { + /* Load attribute for truncated vcn. */ + attr = ni_find_attr(ni, attr_b, &le, ATTR_DATA, NULL, 0, + &vcn, &mi); + if (!attr) { + err = -EINVAL; + goto out; + } + svcn = le64_to_cpu(attr->nres.svcn); + evcn1 = le64_to_cpu(attr->nres.evcn) + 1; + err = attr_load_runs(attr, ni, run, NULL); + if (err) + goto out; + } + } + + if (vcn + to_alloc > asize) + to_alloc = asize - vcn; + /* Get the last LCN to allocate from. */ hint = 0; @@ -980,18 +1032,33 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, hint = -1; } - err = attr_allocate_clusters( - sbi, run, vcn, hint + 1, to_alloc, NULL, 0, len, - (sbi->record_size - le32_to_cpu(mi->mrec->used) + 8) / 3 + 1, - lcn); + /* Allocate and zeroout new clusters. */ + err = attr_allocate_clusters(sbi, run, vcn, hint + 1, to_alloc, NULL, + zero ? ALLOCATE_ZERO : ALLOCATE_DEF, &alen, + fr, lcn, len); if (err) goto out; *new = true; - end = vcn + *len; - + end = vcn + alen; total_size = le64_to_cpu(attr_b->nres.total_size) + - ((u64)*len << cluster_bits); + ((u64)alen << cluster_bits); + + if (vcn != vcn0) { + if (!run_lookup_entry(run, vcn0, lcn, len, NULL)) { + err = -EINVAL; + goto out; + } + if (*lcn == SPARSE_LCN) { + /* Internal error. Should not happened. */ + WARN_ON(1); + err = -EINVAL; + goto out; + } + /* Check case when vcn0 + len overlaps new allocated clusters. */ + if (vcn0 + *len > end) + *len = end - vcn0; + } repack: err = mi_pack_runs(mi, attr, run, max(end, evcn1) - svcn); @@ -1516,7 +1583,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size, struct ATTRIB *attr = NULL, *attr_b; struct ATTR_LIST_ENTRY *le, *le_b; struct mft_inode *mi, *mi_b; - CLST svcn, evcn1, next_svcn, lcn, len; + CLST svcn, evcn1, next_svcn, len; CLST vcn, end, clst_data; u64 total_size, valid_size, data_size; @@ -1592,8 +1659,9 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size, } err = attr_allocate_clusters(sbi, run, vcn + clst_data, - hint + 1, len - clst_data, NULL, 0, - &alen, 0, &lcn); + hint + 1, len - clst_data, NULL, + ALLOCATE_DEF, &alen, 0, NULL, + NULL); if (err) goto out; diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 96ba3f5a8470..63aef132e529 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -122,8 +122,8 @@ static int ntfs_extend_initialized_size(struct file *file, bits = sbi->cluster_bits; vcn = pos >> bits; - err = attr_data_get_block(ni, vcn, 0, &lcn, &clen, - NULL); + err = attr_data_get_block(ni, vcn, 1, &lcn, &clen, NULL, + false); if (err) goto out; @@ -180,18 +180,18 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to) struct address_space *mapping = inode->i_mapping; u32 blocksize = 1 << inode->i_blkbits; pgoff_t idx = vbo >> PAGE_SHIFT; - u32 z_start = vbo & (PAGE_SIZE - 1); + u32 from = vbo & (PAGE_SIZE - 1); pgoff_t idx_end = (vbo_to + PAGE_SIZE - 1) >> PAGE_SHIFT; loff_t page_off; struct buffer_head *head, *bh; - u32 bh_next, bh_off, z_end; + u32 bh_next, bh_off, to; sector_t iblock; struct page *page; - for (; idx < idx_end; idx += 1, z_start = 0) { + for (; idx < idx_end; idx += 1, from = 0) { page_off = (loff_t)idx << PAGE_SHIFT; - z_end = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) - : PAGE_SIZE; + to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) + : PAGE_SIZE; iblock = page_off >> inode->i_blkbits; page = find_or_create_page(mapping, idx, @@ -208,7 +208,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to) do { bh_next = bh_off + blocksize; - if (bh_next <= z_start || bh_off >= z_end) + if (bh_next <= from || bh_off >= to) continue; if (!buffer_mapped(bh)) { @@ -242,7 +242,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to) } while (bh_off = bh_next, iblock += 1, head != (bh = bh->b_this_page)); - zero_user_segment(page, z_start, z_end); + zero_user_segment(page, from, to); unlock_page(page); put_page(page); @@ -253,80 +253,6 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to) return err; } -/* - * ntfs_sparse_cluster - Helper function to zero a new allocated clusters. - * - * NOTE: 512 <= cluster size <= 2M - */ -void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn, - CLST len) -{ - struct address_space *mapping = inode->i_mapping; - struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info; - u8 cluster_bits = sbi->cluster_bits; - u64 vbo = (u64)vcn << cluster_bits; - u64 bytes = (u64)len << cluster_bits; - u32 blocksize = 1 << inode->i_blkbits; - pgoff_t idx0 = page0 ? page0->index : -1; - loff_t vbo_clst = vbo & sbi->cluster_mask_inv; - loff_t end = ntfs_up_cluster(sbi, vbo + bytes); - pgoff_t idx = vbo_clst >> PAGE_SHIFT; - u32 from = vbo_clst & (PAGE_SIZE - 1); - pgoff_t idx_end = (end + PAGE_SIZE - 1) >> PAGE_SHIFT; - loff_t page_off; - u32 to; - bool partial; - struct page *page; - - for (; idx < idx_end; idx += 1, from = 0) { - page = idx == idx0 ? page0 : grab_cache_page(mapping, idx); - - if (!page) - continue; - - page_off = (loff_t)idx << PAGE_SHIFT; - to = (page_off + PAGE_SIZE) > end ? (end - page_off) - : PAGE_SIZE; - partial = false; - - if ((from || PAGE_SIZE != to) && - likely(!page_has_buffers(page))) { - create_empty_buffers(page, blocksize, 0); - } - - if (page_has_buffers(page)) { - struct buffer_head *head, *bh; - u32 bh_off = 0; - - bh = head = page_buffers(page); - do { - u32 bh_next = bh_off + blocksize; - - if (from <= bh_off && bh_next <= to) { - set_buffer_uptodate(bh); - mark_buffer_dirty(bh); - } else if (!buffer_uptodate(bh)) { - partial = true; - } - bh_off = bh_next; - } while (head != (bh = bh->b_this_page)); - } - - zero_user_segment(page, from, to); - - if (!partial) - SetPageUptodate(page); - flush_dcache_page(page); - set_page_dirty(page); - - if (idx != idx0) { - unlock_page(page); - put_page(page); - } - cond_resched(); - } -} - /* * ntfs_file_mmap - file_operations::mmap */ @@ -368,13 +294,9 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma) for (; vcn < end; vcn += len) { err = attr_data_get_block(ni, vcn, 1, &lcn, - &len, &new); + &len, &new, true); if (err) goto out; - - if (!new) - continue; - ntfs_sparse_cluster(inode, NULL, vcn, 1); } } @@ -518,7 +440,8 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) struct ntfs_sb_info *sbi = sb->s_fs_info; struct ntfs_inode *ni = ntfs_i(inode); loff_t end = vbo + len; - loff_t vbo_down = round_down(vbo, PAGE_SIZE); + loff_t vbo_down = round_down(vbo, max_t(unsigned long, + sbi->cluster_size, PAGE_SIZE)); bool is_supported_holes = is_sparsed(ni) || is_compressed(ni); loff_t i_size, new_size; bool map_locked; @@ -571,7 +494,8 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) u32 frame_size; loff_t mask, vbo_a, end_a, tmp; - err = filemap_write_and_wait_range(mapping, vbo, LLONG_MAX); + err = filemap_write_and_wait_range(mapping, vbo_down, + LLONG_MAX); if (err) goto out; @@ -672,39 +596,35 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) goto out; if (is_supported_holes) { - CLST vcn_v = bytes_to_cluster(sbi, ni->i_valid); CLST vcn = vbo >> sbi->cluster_bits; CLST cend = bytes_to_cluster(sbi, end); + CLST cend_v = bytes_to_cluster(sbi, ni->i_valid); CLST lcn, clen; bool new; + if (cend_v > cend) + cend_v = cend; + /* - * Allocate but do not zero new clusters. (see below comments) - * This breaks security: One can read unused on-disk areas. + * Allocate and zero new clusters. * Zeroing these clusters may be too long. - * Maybe we should check here for root rights? + */ + for (; vcn < cend_v; vcn += clen) { + err = attr_data_get_block(ni, vcn, cend_v - vcn, + &lcn, &clen, &new, + true); + if (err) + goto out; + } + /* + * Allocate but not zero new clusters. */ for (; vcn < cend; vcn += clen) { err = attr_data_get_block(ni, vcn, cend - vcn, - &lcn, &clen, &new); + &lcn, &clen, &new, + false); if (err) goto out; - if (!new || vcn >= vcn_v) - continue; - - /* - * Unwritten area. - * NTFS is not able to store several unwritten areas. - * Activate 'ntfs_sparse_cluster' to zero new allocated clusters. - * - * Dangerous in case: - * 1G of sparsed clusters + 1 cluster of data => - * valid_size == 1G + 1 cluster - * fallocate(1G) will zero 1G and this can be very long - * xfstest 016/086 will fail without 'ntfs_sparse_cluster'. - */ - ntfs_sparse_cluster(inode, NULL, vcn, - min(vcn_v - vcn, clen)); } } @@ -925,8 +845,8 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from) frame_vbo = valid & ~(frame_size - 1); off = valid & (frame_size - 1); - err = attr_data_get_block(ni, frame << NTFS_LZNT_CUNIT, 0, &lcn, - &clen, NULL); + err = attr_data_get_block(ni, frame << NTFS_LZNT_CUNIT, 1, &lcn, + &clen, NULL, false); if (err) goto out; diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index a7aed31e7c93..370c6398a044 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -2224,7 +2224,7 @@ int ni_decompress_file(struct ntfs_inode *ni) for (vcn = vbo >> sbi->cluster_bits; vcn < end; vcn += clen) { err = attr_data_get_block(ni, vcn, cend - vcn, &lcn, - &clen, &new); + &clen, &new, false); if (err) goto out; } diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 50c90d7e8a78..bc9ab93db1d0 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1347,8 +1347,8 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni, run_init(&run); - err = attr_allocate_clusters(sbi, &run, 0, 0, len, NULL, 0, &alen, 0, - NULL); + err = attr_allocate_clusters(sbi, &run, 0, 0, len, NULL, ALLOCATE_DEF, + &alen, 0, NULL, NULL); if (err) goto out; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index f487d36c9b78..18edbc7b35df 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -576,7 +576,8 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, off = vbo & sbi->cluster_mask; new = false; - err = attr_data_get_block(ni, vcn, 1, &lcn, &len, create ? &new : NULL); + err = attr_data_get_block(ni, vcn, 1, &lcn, &len, create ? &new : NULL, + create && sbi->cluster_size > PAGE_SIZE); if (err) goto out; @@ -594,11 +595,8 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, WARN_ON(1); } - if (new) { + if (new) set_buffer_new(bh); - if ((len << cluster_bits) > block_size) - ntfs_sparse_cluster(inode, page, vcn, len); - } lbo = ((u64)lcn << cluster_bits) + off; @@ -1529,8 +1527,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, cpu_to_le64(ntfs_up_cluster(sbi, nsize)); err = attr_allocate_clusters(sbi, &ni->file.run, 0, 0, - clst, NULL, 0, &alen, 0, - NULL); + clst, NULL, ALLOCATE_DEF, + &alen, 0, NULL, NULL); if (err) goto out5; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index e9f6898ec924..c45a411f82f6 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -126,6 +126,7 @@ struct ntfs_buffers { enum ALLOCATE_OPT { ALLOCATE_DEF = 0, // Allocate all clusters. ALLOCATE_MFT = 1, // Allocate for MFT. + ALLOCATE_ZERO = 2, // Zeroout new allocated clusters }; enum bitmap_mutex_classes { @@ -414,7 +415,7 @@ enum REPARSE_SIGN { int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run, CLST vcn, CLST lcn, CLST len, CLST *pre_alloc, enum ALLOCATE_OPT opt, CLST *alen, const size_t fr, - CLST *new_lcn); + CLST *new_lcn, CLST *new_len); int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr, struct ATTR_LIST_ENTRY *le, struct mft_inode *mi, u64 new_size, struct runs_tree *run, @@ -424,7 +425,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, u64 new_size, const u64 *new_valid, bool keep_prealloc, struct ATTRIB **ret); int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, - CLST *len, bool *new); + CLST *len, bool *new, bool zero); int attr_data_read_resident(struct ntfs_inode *ni, struct page *page); int attr_data_write_resident(struct ntfs_inode *ni, struct page *page); int attr_load_runs_vcn(struct ntfs_inode *ni, enum ATTR_TYPE type, @@ -489,8 +490,6 @@ extern const struct file_operations ntfs_dir_operations; /* Globals from file.c */ int ntfs_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 request_mask, u32 flags); -void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn, - CLST len); int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, struct iattr *attr); int ntfs_file_open(struct inode *inode, struct file *file); From patchwork Fri Oct 28 17:02:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp942186wru; Fri, 28 Oct 2022 10:05:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rKqroGWUgX14KJ8UEYVuCT5xWfJ2BMQ8LaBr9h11y8ivqCxhtR0iGVicLqIEHPYPpICkX X-Received: by 2002:a05:6402:440f:b0:45d:297b:c70a with SMTP id y15-20020a056402440f00b0045d297bc70amr388679eda.187.1666976719529; Fri, 28 Oct 2022 10:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976719; cv=none; d=google.com; s=arc-20160816; b=A7JIuYEhQT1ntw5jZG7H5+EFl0xweNTQ01I3PPGrCQQ8XSYQDP5yi+VAFch8CIxZFH dt+I1Rs+GLjdxJQJZZhCk1HWSDdiwvz7Ly8PSOylJEUyYBbOUgESOOWHmXhet819LAy/ MryGzlGJIe9/FRu4wyd/7iLeAoh74VJ4PA4gXFiE/vGod8SeKOJ/fF5YklmXZcvu4o0B ggTJ+0WXZF5/3sMKe/2LdjvU8+B/H4YHWIDUufJrGRenb5Kibvb7Lr/fMs6jmp0z2F7n Lz1tFXp2TVDQEW3t/4+kZMbFqg6akGeemp6G+9c6YzvWtEQLkfn2zLutcvC6O3GxGA49 DcHg== 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=/mJlfZpKQiISMX08oxRpKAnkO7e2Q5yFIpcw3wftSqA=; b=vaRqggz77LM6a3nSPSDfYNFaQFUu6xv0wvEZtXe18ig6vV2ATCalyiBpmastqfvST1 2Q1qpyT6xJHrxYKdr5VCmuKgQ2evZ3bH8EGQnsI6SD9dN5tgWPt7MV31dwyAbEKa3U2G qAz4Sssu8jf+AIBJN0gf2pveKjBttKP0rJyEgeYwFLhRFpSStgptskOzT48d+JOb79zY anS74zeCJfPcv855IpyrxE4Vq7kv9TZfV6sooh5kvgewD2yJZI7ZHOphdzFnGyvPwTH4 56sEqL5Sm3/hxmd9wdrD9Bj/NGo3sA/d2P+40WkXNub2eMksiTV482oHosx9NIv9UwP4 FHOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="o/smmKU0"; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ok6hQPEi; 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 w16-20020a056402269000b00462a87b0546si5242510edd.607.2022.10.28.10.04.44; Fri, 28 Oct 2022 10:05:19 -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="o/smmKU0"; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ok6hQPEi; 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 S230334AbiJ1RER (ORCPT + 99 others); Fri, 28 Oct 2022 13:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiJ1RD7 (ORCPT ); Fri, 28 Oct 2022 13:03: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 AD4117C74D; Fri, 28 Oct 2022 10:02:59 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id BB693218D; Fri, 28 Oct 2022 17:00:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976418; bh=/mJlfZpKQiISMX08oxRpKAnkO7e2Q5yFIpcw3wftSqA=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=o/smmKU0axmJVk+bWKQYA8tJM7Bcix5OROTciVjH4DN5LHz7y+htVHZ0pj667fdnw 20CJztmqj5p0wPVUPm9qFr9SpqMNLQz1QM7Ryr01t7EAlLvbtzvqILonk1BJB2loZq oYVjgy+VPls0jpJQvLUiYAFf2PiRwD7wSl1BOb6U= 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 B3FFDDD; Fri, 28 Oct 2022 17:02:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976577; bh=/mJlfZpKQiISMX08oxRpKAnkO7e2Q5yFIpcw3wftSqA=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ok6hQPEiCLvCjCtq1SSO+CfMUFC+fzXIKSX7vR9jqK2GOvwf+cJJsxzg7Da4XLSae 9GJZ/Wg6RJ9wYjFOSMDYJe2QQnJjEAQKrYhjyc/KAicmIuptR69nS53FJ0B/oqp5Jp 6XgwLZc+J8GUc1D8K/xV2iV2NdGTY8AYlKLuKVus= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:02:57 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:02:57 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 03/14] fs/ntfs3: Fix wrong indentations Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747951780692990368?= X-GMAIL-MSGID: =?utf-8?q?1747951780692990368?= Also simplifying code. Signed-off-by: Konstantin Komarov --- fs/ntfs3/fslog.c | 3 +-- fs/ntfs3/index.c | 8 ++++---- fs/ntfs3/inode.c | 8 +++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index 5289c25b1ee4..e61545b9772e 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -4824,8 +4824,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) goto out; } attr = oa->attr; - t64 = le64_to_cpu(attr->nres.alloc_size); - if (size > t64) { + if (size > le64_to_cpu(attr->nres.alloc_size)) { attr->nres.valid_size = attr->nres.data_size = attr->nres.alloc_size = cpu_to_le64(size); } diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index bc9ab93db1d0..a2e1e07b5bb8 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -625,9 +625,8 @@ void fnd_clear(struct ntfs_fnd *fnd) static int fnd_push(struct ntfs_fnd *fnd, struct indx_node *n, struct NTFS_DE *e) { - int i; + int i = fnd->level; - i = fnd->level; if (i < 0 || i >= ARRAY_SIZE(fnd->nodes)) return -EINVAL; fnd->nodes[i] = n; @@ -2121,9 +2120,10 @@ static int indx_get_entry_to_replace(struct ntfs_index *indx, fnd->de[level] = e; indx_write(indx, ni, n, 0); - /* Check to see if this action created an empty leaf. */ - if (ib_is_leaf(ib) && ib_is_empty(ib)) + if (ib_is_leaf(ib) && ib_is_empty(ib)) { + /* An empty leaf. */ return 0; + } out: fnd_clear(fnd); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 18edbc7b35df..df0d30a3218a 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1810,11 +1810,12 @@ static int ntfs_translate_junction(const struct super_block *sb, /* Make translated path a relative path to mount point */ strcpy(translated, "./"); - ++link_path; /* Skip leading / */ + ++link_path; /* Skip leading / */ for (tl_len = sizeof("./") - 1; *link_path; ++link_path) { if (*link_path == '/') { if (PATH_MAX - tl_len < sizeof("../")) { - ntfs_err(sb, "Link path %s has too many components", + ntfs_err(sb, + "Link path %s has too many components", link_path); err = -EINVAL; goto out; @@ -1830,7 +1831,8 @@ static int ntfs_translate_junction(const struct super_block *sb, ++target_start; if (!*target_start) { - ntfs_err(sb, "Link target (%s) missing drive separator", target); + ntfs_err(sb, "Link target (%s) missing drive separator", + target); err = -EINVAL; goto out; } From patchwork Fri Oct 28 17:03:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp942531wru; Fri, 28 Oct 2022 10:05:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7R9pqYlxujViwPMjvYTeG3JTHmTWePVGce3AXoS/GBWgcMt91Es2LtSa/R4OCZzTzw3RzF X-Received: by 2002:a17:906:591:b0:73d:c3ef:84ae with SMTP id 17-20020a170906059100b0073dc3ef84aemr286476ejn.155.1666976752267; Fri, 28 Oct 2022 10:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976752; cv=none; d=google.com; s=arc-20160816; b=EMkH2beI1GRe7Z+Gcy2qPMmI6akB5WgzIvVNOiFG+LwQYuk/oaxG+8U0bfbQcqehEd xW6ktfyEGLe2RwIB1ZvQOvJyCw1ILzJac/Q1JfvFTQsPqGwVKxyIph2QoGsaiQ7o4Y3b JGot+FfKylOz9hQgIvLMtwgXRAaokO4NVO13JLrP0/e8HMO7HiGPj8rtUEolH7vZUiRL OZ2HYBzTxjhLA9Jep9++uiy64fHzP8M7lnV0bNeem6bwPTmUh4+CXIMs8FZqJcwhHRg6 b1UqzYQFHeYx0j2zpWQ5+gM1JoCJWgTJcA0A/RYbyvp69fPrfkEl/Z/wT6C1lh9YtIMU NPJg== 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=Ls7WiocB2yL0aysOFrJdtUMz+tZ1iGtxcZz+VnGx4UU=; b=GL0mgkKbnLNdfE5Tv0woZlh+b8inCgYhzB5wGqg0S4zv6qJJRUcFG58io3u6tuBUC5 hWJNAi9J4sETQQGR4DjZ7xxGEfjbB01x1jL88GRcA4kI9twEmwRodQxC3rnEjVaajNae y4Rd/LnFpYavPzhn7USTbqVV6DuZHNjt7LRhX2QEcECjvSDghoTRCrXC2ResKX+EY1R/ mArKkLT+kB0cSv7KVkJIB6Wf8VAvKBUxKcrsaMH4IDmsosEfAQLTgDKiF4+5XjXafEUf IIFsV8L3npeesQca7IVpOqmoTCaQoEUKJpV09++8eS0yr0UMNZieZx4cv5LkErvOoDbs L/Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=B13mD9jD; 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 jg3-20020a170907970300b00730a4246dd0si6009521ejc.593.2022.10.28.10.05.20; Fri, 28 Oct 2022 10:05:52 -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=B13mD9jD; 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 S230460AbiJ1REr (ORCPT + 99 others); Fri, 28 Oct 2022 13:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbiJ1REK (ORCPT ); Fri, 28 Oct 2022 13:04:10 -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 7857D7CE0B; Fri, 28 Oct 2022 10:03:26 -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 97669218D; Fri, 28 Oct 2022 17:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976445; bh=Ls7WiocB2yL0aysOFrJdtUMz+tZ1iGtxcZz+VnGx4UU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=B13mD9jDlaE4YIXPyBWy6kl77Zf4g00kUZ4cnlFynxV+alTW8AbZ/JCvCtJPMneXF ZkGqYMfMl5qb5IH0SmpULWJt0qAMmPCOVcb9vQBU97xgPBVoOeFCZG0ZnLsKwLEKrV Ti014Xqg8xc34npJBlD3g078+1h9vqR37ErU7bA4= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:03:24 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:03:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 04/14] fs/ntfs3: atomic_open implementation Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747951814969512693?= X-GMAIL-MSGID: =?utf-8?q?1747951814969512693?= Added ntfs_atomic_open function. Relaxed locking in ntfs_create_inode. Signed-off-by: Konstantin Komarov --- fs/ntfs3/inode.c | 24 ++++++++++-- fs/ntfs3/namei.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index df0d30a3218a..405afb54cc19 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1183,6 +1183,18 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname, return ERR_PTR(err); } +/* + * ntfs_create_inode + * + * Helper function for: + * - ntfs_create + * - ntfs_mknod + * - ntfs_symlink + * - ntfs_mkdir + * - ntfs_atomic_open + * + * NOTE: if fnd != NULL (ntfs_atomic_open) then @dir is locked + */ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, const struct cpu_str *uni, umode_t mode, @@ -1212,7 +1224,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, struct REPARSE_DATA_BUFFER *rp = NULL; bool rp_inserted = false; - ni_lock_dir(dir_ni); + if (!fnd) + ni_lock_dir(dir_ni); dir_root = indx_get_root(&dir_ni->dir, dir_ni, NULL, NULL); if (!dir_root) { @@ -1575,7 +1588,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, goto out6; /* Unlock parent directory before ntfs_init_acl. */ - ni_unlock(dir_ni); + if (!fnd) + ni_unlock(dir_ni); inode->i_generation = le16_to_cpu(rec->seq); @@ -1635,7 +1649,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, out7: /* Undo 'indx_insert_entry'. */ - ni_lock_dir(dir_ni); + if (!fnd) + ni_lock_dir(dir_ni); indx_delete_entry(&dir_ni->dir, dir_ni, new_de + 1, le16_to_cpu(new_de->key_size), sbi); /* ni_unlock(dir_ni); will be called later. */ @@ -1663,7 +1678,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, out1: if (err) { - ni_unlock(dir_ni); + if (!fnd) + ni_unlock(dir_ni); return ERR_PTR(err); } diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index ff76389475ad..1af02d4f6b4d 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "debug.h" #include "ntfs.h" @@ -334,6 +335,104 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir, return err; } +/* + * ntfs_atomic_open + * + * inode_operations::atomic_open + */ +static int ntfs_atomic_open(struct inode *dir, struct dentry *dentry, + struct file *file, u32 flags, umode_t mode) +{ + int err; + struct inode *inode; + struct ntfs_fnd *fnd = NULL; + struct ntfs_inode *ni = ntfs_i(dir); + struct dentry *d = NULL; + struct cpu_str *uni = __getname(); + bool locked = false; + + if (!uni) + return -ENOMEM; + + err = ntfs_nls_to_utf16(ni->mi.sbi, dentry->d_name.name, + dentry->d_name.len, uni, NTFS_NAME_LEN, + UTF16_HOST_ENDIAN); + if (err < 0) + goto out; + +#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 + */ + struct posix_acl *p = get_acl(dir, ACL_TYPE_DEFAULT); + + if (IS_ERR(p)) { + err = PTR_ERR(p); + goto out; + } + posix_acl_release(p); + } +#endif + + if (d_in_lookup(dentry)) { + ni_lock_dir(ni); + locked = true; + fnd = fnd_get(); + if (!fnd) { + err = -ENOMEM; + goto out1; + } + + d = d_splice_alias(dir_search_u(dir, uni, fnd), dentry); + if (IS_ERR(d)) { + err = PTR_ERR(d); + d = NULL; + goto out2; + } + + if (d) + dentry = d; + } + + if (!(flags & O_CREAT) || d_really_is_positive(dentry)) { + err = finish_no_open(file, d); + goto out2; + } + + file->f_mode |= FMODE_CREATED; + + /* + * fnd contains tree's path to insert to. + * If fnd is not NULL then dir is locked. + */ + + /* + * Unfortunately I don't know how to get here correct 'struct nameidata *nd' + * or 'struct user_namespace *mnt_userns'. + * See atomic_open in fs/namei.c. + * This is why xfstest/633 failed. + * Looks like ntfs_atomic_open must accept 'struct user_namespace *mnt_userns' as argument. + */ + + inode = ntfs_create_inode(&init_user_ns, dir, dentry, uni, mode, 0, + NULL, 0, fnd); + err = IS_ERR(inode) ? PTR_ERR(inode) + : finish_open(file, dentry, ntfs_file_open); + dput(d); + +out2: + fnd_put(fnd); +out1: + if (locked) + ni_unlock(ni); +out: + __putname(uni); + return err; +} + struct dentry *ntfs3_get_parent(struct dentry *child) { struct inode *inode = d_inode(child); @@ -504,6 +603,7 @@ const struct inode_operations ntfs_dir_inode_operations = { .setattr = ntfs3_setattr, .getattr = ntfs_getattr, .listxattr = ntfs_listxattr, + .atomic_open = ntfs_atomic_open, .fiemap = ntfs_fiemap, }; From patchwork Fri Oct 28 17:03:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp943016wru; Fri, 28 Oct 2022 10:06:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CgLGb/IZGMF/Ja1Gjz3uH6WsRgldpfI+Y74wdCUUe0oSa1JumkDLbtfefKTdACwgPDsir X-Received: by 2002:a17:907:7f8e:b0:7aa:7598:126d with SMTP id qk14-20020a1709077f8e00b007aa7598126dmr298370ejc.289.1666976806869; Fri, 28 Oct 2022 10:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976806; cv=none; d=google.com; s=arc-20160816; b=ZV3T8SXikNND+H1wny/XxFCvQKH+KAxQZw8RCHkZoCqtZvXmT0+ces8i/x8TYKb998 XA0TytMM3M7bwMgrwjS0r+eRh/kxB/fTCg+6cgnHxwzTbI9jHlUuvSKRCZaxgjq5shWZ +bVuz7NM+tro7dxlsBBP8Ih2O9ePrfg3q97oxIhd6jhYZ5EcxW9zs6DU9/LXSK0QFMjC DXTbb4U5vfeT2ZByu97QLyEnbFP7Pghi2bsEVjemJi8PUUPbVUpAr53bj5g6301kDZbb bXv+cXzwkVwqpKre8dOeK8msNWqei2knCnwJ8wi1Cd6FlB2faYuyMmNehYgPHG3DfTfA m9vQ== 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=7CPKDDVsSnfhQv2FIDQRZDeSJd/QzjNRDoHBpF6DsHc=; b=qux8GEU++7joNTIBNH7zqHr97R5qv6bmiR3svV/M9Hn1JPoIgI1m6WNSbrXiDGBYHk QKxHGQPDloGOdNjStNtqq81JO68JY+QL9oQX2MgKfMqEtalz4Ckwj+le5zbr/K/Oj5tW Vg/JH2tJK+RQUWz9mITVCQ9D9CqprD5A7VKeC3r7beUtlhTCywFy/O3GADmUdQhG8Bve XAJvRHA1PaZxu4GB6RCF7H6YbIX/iO8j4ik3ye4l0nVzDUhW0xE2LZjhkT6pghow5WGZ H3JNEvECuIzlBQkhzyoojxHucHp7vycuIwRR80XGKSLh2X+6ZxT5f7Iuc8u1a2f8i1tP 2Qjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=NHENqJ9Q; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZtwaZy3j; 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 h4-20020a056402280400b0045440929f87si2448822ede.86.2022.10.28.10.06.18; Fri, 28 Oct 2022 10:06:46 -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=NHENqJ9Q; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZtwaZy3j; 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 S231279AbiJ1RFS (ORCPT + 99 others); Fri, 28 Oct 2022 13:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbiJ1REU (ORCPT ); Fri, 28 Oct 2022 13:04:20 -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 7D32D22D5F0; Fri, 28 Oct 2022 10:03:56 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 9BA2D218D; Fri, 28 Oct 2022 17:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976475; bh=7CPKDDVsSnfhQv2FIDQRZDeSJd/QzjNRDoHBpF6DsHc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=NHENqJ9QiBWV1u1KbsanQe8xs5FBr8mTnQhxFnENOfFJMFR3mLFu9crLcdCHSBHuH 0dywRoB4lG8wZlfLFs4ad8ZiC/6j/Iki0Wc2aLbofhBI9fAqPCGPJ0bImQcqUwWEXh 5UMefF0H9LrLoAieK/OQjaYQcF89i8H5rXFc1zXk= 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 97A68DD; Fri, 28 Oct 2022 17:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976634; bh=7CPKDDVsSnfhQv2FIDQRZDeSJd/QzjNRDoHBpF6DsHc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ZtwaZy3jXCrm0t26DkS0rm4OCn2jQRYOZ/50MvH6FSnC1I05902RZAwzuTt22iS0n y2927ENmvKF44rdhcUtPpMdoEm0l7B00MjKSwopN/CT9Un/uAScaNI+MdkIrYDB+sS 0NIVY9BTIykVJvLMpF8PQuPP8AJZHYCZKsxnOifE= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:03:54 +0300 Message-ID: <5f006fed-743e-336a-ea14-699c376215e7@paragon-software.com> Date: Fri, 28 Oct 2022 20:03:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 05/14] fs/ntfs3: Fixing wrong logic in attr_set_size and ntfs_fallocate Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747951871863187879?= X-GMAIL-MSGID: =?utf-8?q?1747951871863187879?= There were 2 problems: - in some cases we lost dirty flag; - cluster allocation can be called even when it wasn't needed. Fixes xfstest generic/465 Signed-off-by: Konstantin Komarov --- fs/ntfs3/attrib.c | 25 +++++++++++-------------- fs/ntfs3/file.c | 30 ++++++++++++++++++------------ fs/ntfs3/index.c | 9 +++++++++ fs/ntfs3/inode.c | 17 +++++------------ 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index eda83a37a0c3..91ea73e6f4fe 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -414,6 +414,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST alen, vcn, lcn, new_alen, old_alen, svcn, evcn; CLST next_svcn, pre_alloc = -1, done = 0; bool is_ext, is_bad = false; + bool dirty = false; u32 align; struct MFT_REC *rec; @@ -434,8 +435,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, return err; /* Return if file is still resident. */ - if (!attr_b->non_res) + if (!attr_b->non_res) { + dirty = true; goto ok1; + } /* Layout of records may be changed, so do a full search. */ goto again; @@ -458,7 +461,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, if (keep_prealloc && new_size < old_size) { attr_b->nres.data_size = cpu_to_le64(new_size); - mi_b->dirty = true; + mi_b->dirty = dirty = true; goto ok; } @@ -504,7 +507,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, if (new_alloc <= old_alloc) { attr_b->nres.data_size = cpu_to_le64(new_size); - mi_b->dirty = true; + mi_b->dirty = dirty = true; goto ok; } @@ -595,7 +598,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, next_svcn = le64_to_cpu(attr->nres.evcn) + 1; new_alloc_tmp = (u64)next_svcn << cluster_bits; attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp); - mi_b->dirty = true; + mi_b->dirty = dirty = true; if (next_svcn >= vcn && !to_allocate) { /* Normal way. Update attribute and exit. */ @@ -681,7 +684,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, old_valid = old_size = old_alloc = (u64)vcn << cluster_bits; attr_b->nres.valid_size = attr_b->nres.data_size = attr_b->nres.alloc_size = cpu_to_le64(old_size); - mi_b->dirty = true; + mi_b->dirty = dirty = true; goto again_1; } @@ -743,7 +746,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, attr_b->nres.valid_size = attr_b->nres.alloc_size; } - mi_b->dirty = true; + mi_b->dirty = dirty = true; err = run_deallocate_ex(sbi, run, vcn, evcn - vcn + 1, &dlen, true); @@ -804,16 +807,9 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, if (ret) *ret = attr_b; - /* Update inode_set_bytes. */ if (((type == ATTR_DATA && !name_len) || (type == ATTR_ALLOC && name == I30_NAME))) { - bool dirty = false; - - if (ni->vfs_inode.i_size != new_size) { - ni->vfs_inode.i_size = new_size; - dirty = true; - } - + /* Update inode_set_bytes. */ if (attr_b->non_res) { new_alloc = le64_to_cpu(attr_b->nres.alloc_size); if (inode_get_bytes(&ni->vfs_inode) != new_alloc) { @@ -822,6 +818,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, } } + /* Don't forget to update duplicate information in parent. */ if (dirty) { ni->ni_flags |= NI_FLAG_UPDATE_PARENT; mark_inode_dirty(&ni->vfs_inode); diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 63aef132e529..511e58f2b0f8 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -337,7 +337,6 @@ static int ntfs_extend(struct inode *inode, loff_t pos, size_t count, err = ntfs_set_size(inode, end); if (err) goto out; - inode->i_size = end; } if (extend_init && !is_compressed(ni)) { @@ -588,12 +587,14 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) if (err) goto out; - /* - * Allocate clusters, do not change 'valid' size. - */ - err = ntfs_set_size(inode, new_size); - if (err) - goto out; + if (new_size > i_size) { + /* + * Allocate clusters, do not change 'valid' size. + */ + err = ntfs_set_size(inode, new_size); + if (err) + goto out; + } if (is_supported_holes) { CLST vcn = vbo >> sbi->cluster_bits; @@ -635,6 +636,8 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len) &ni->file.run, i_size, &ni->i_valid, true, NULL); ni_unlock(ni); + } else if (new_size > i_size) { + inode->i_size = new_size; } } @@ -678,7 +681,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, goto out; if (ia_valid & ATTR_SIZE) { - loff_t oldsize = inode->i_size; + loff_t newsize, oldsize; if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) { /* Should never be here, see ntfs_file_open(). */ @@ -686,16 +689,19 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, goto out; } inode_dio_wait(inode); + oldsize = inode->i_size; + newsize = attr->ia_size; - if (attr->ia_size <= oldsize) - err = ntfs_truncate(inode, attr->ia_size); - else if (attr->ia_size > oldsize) - err = ntfs_extend(inode, attr->ia_size, 0, NULL); + if (newsize <= oldsize) + err = ntfs_truncate(inode, newsize); + else + err = ntfs_extend(inode, newsize, 0, NULL); if (err) goto out; ni->ni_flags |= NI_FLAG_UPDATE_PARENT; + inode->i_size = newsize; } setattr_copy(mnt_userns, inode, attr); diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index a2e1e07b5bb8..35369ae5c438 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1445,6 +1445,9 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni, goto out1; } + if (in->name == I30_NAME) + ni->vfs_inode.i_size = data_size; + *vbn = bit << indx->idx2vbn_bits; return 0; @@ -1978,6 +1981,9 @@ static int indx_shrink(struct ntfs_index *indx, struct ntfs_inode *ni, if (err) return err; + if (in->name == I30_NAME) + ni->vfs_inode.i_size = new_data; + bpb = bitmap_size(bit); if (bpb * 8 == nbits) return 0; @@ -2461,6 +2467,9 @@ int indx_delete_entry(struct ntfs_index *indx, struct ntfs_inode *ni, err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len, &indx->alloc_run, 0, NULL, false, NULL); + if (in->name == I30_NAME) + ni->vfs_inode.i_size = 0; + err = ni_remove_attr(ni, ATTR_ALLOC, in->name, in->name_len, false, NULL); run_close(&indx->alloc_run); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 405afb54cc19..78ec3e6bbf67 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -550,17 +550,6 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, clear_buffer_new(bh); clear_buffer_uptodate(bh); - /* Direct write uses 'create=0'. */ - if (!create && vbo >= ni->i_valid) { - /* Out of valid. */ - return 0; - } - - if (vbo >= inode->i_size) { - /* Out of size. */ - return 0; - } - if (is_resident(ni)) { ni_lock(ni); err = attr_data_read_resident(ni, page); @@ -624,7 +613,6 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, } } else if (vbo >= valid) { /* Read out of valid data. */ - /* Should never be here 'cause already checked. */ clear_buffer_mapped(bh); } else if (vbo + bytes <= valid) { /* Normal read. */ @@ -974,6 +962,11 @@ int ntfs_write_end(struct file *file, struct address_space *mapping, dirty = true; } + if (pos + err > inode->i_size) { + inode->i_size = pos + err; + dirty = true; + } + if (dirty) mark_inode_dirty(inode); } From patchwork Fri Oct 28 17:04:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp944170wru; Fri, 28 Oct 2022 10:08:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UmBR2qW/kW2TtP1Q4nOQGrhqNBSGA2j5LKfEiCzSeu/uunS+OvmS7kVcZUOp3xHIiUUU7 X-Received: by 2002:a05:6402:c4d:b0:457:99ec:1837 with SMTP id cs13-20020a0564020c4d00b0045799ec1837mr436089edb.86.1666976929493; Fri, 28 Oct 2022 10:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976929; cv=none; d=google.com; s=arc-20160816; b=FTbuA/OkXjtjofpq/eNxaNPF9JU+tonnwBqPeRuZtZKxFmq/3hYKO4pZV8ok2vRMAp uDdwEbOdwSFqDWxrd4nm2iecJXYfvVlRahfYQH29iIydLXVs80y3XEuHgGGunxqouJTe /1Xx7CpZgGlnrPgjWewxbmvP44PoM1nUng0Al8oy06gtfupFwPXlTSJXzmliOGKG/l3+ XLBjkJQfD/MU4khVSIu+EgF3SIjH2XdJlfu8Oke9gN0lE9hbqVe+XgT1DDB+8foIN3ZU KexqFdtGF8dsBhD631OGPF9fC6UzM2xKpm/WU5uDjRExicN/caMGYD1matvlqs0VGoKb vUiA== 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=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; b=UkZDkViBHmHStNWcb+mHWNXx4ZtApk3xh2sRxN6WK4/kPutP2Sf6S2xg5C0NSw7wJI bEUyez2X3EV+8vUFWWU1q9AlNkoxuTkj7I+I6KP2qTwnzrc6z6kUIExewdbo6AFMu/bU 4ZagEhUjxSuO788cx5qYT5f6taXtQth97xYM0BnD9irYFU3+JMobSZnEImTmtY8wuyrK qsKBWrqMU8nSKOb9Za8uCGmzwBA8wPTFVSsQiDPwMtZJwQ9BAXyICNgClENAnGAkfylX T/RBTAErbm5XEc1YIFeawAanzMH6CIYU6OFA/hstqpA/Ny4l/RUXP98F5PBB+Plt9ZFx a81w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=BygQuWcH; dkim=pass header.i=@paragon-software.com header.s=mail header.b=be8RnZNL; 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 c16-20020a50f610000000b00459c2ac54e2si200519edn.255.2022.10.28.10.08.25; Fri, 28 Oct 2022 10:08:49 -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=BygQuWcH; dkim=pass header.i=@paragon-software.com header.s=mail header.b=be8RnZNL; 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 S231266AbiJ1RGc (ORCPT + 99 others); Fri, 28 Oct 2022 13:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbiJ1RFZ (ORCPT ); Fri, 28 Oct 2022 13:05:25 -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 86B675F65; Fri, 28 Oct 2022 10:04:29 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 5525A218D; Fri, 28 Oct 2022 17:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976508; bh=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=BygQuWcHrtPlllKZ5K86ExroWKnBzp7tyPVA1fSldWehIIebhqr1t4xpqbY6LA5t4 d+gQ+9ApkUIifzZ61+sWm4gaBdzDtg5325q/kkF1ynKcUHOxY4dKSX66/y7z9H0nvn Q6yspqKR4aM8atx8zL2McYxz3BvVOBKO9qkLyUz0= 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 5336DDD; Fri, 28 Oct 2022 17:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976667; bh=BmUVG6ms7j9t1XfpPFgVhAO9DJJUmMgqjadwiLxmTcw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=be8RnZNLcEwCgSEyGxTN3VMSaPn1aEaicmyBZxAVejZb5/hOiuE8FHUcaTd2PVPoW YsGUoMcoqbi+rgmjWN5yRf7QczlRiEsNKepU9WTtackXhpl39HE79RwMkgPVpyqCAu dW+OnKeiRAK6IuMlpxhGQWBuGHfYeMemfa8pwrYo= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:04:26 +0300 Message-ID: <721e9a74-607c-fb85-8cbf-5bfed49b266e@paragon-software.com> Date: Fri, 28 Oct 2022 20:04:26 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 06/14] fs/ntfs3: Changing locking in ntfs_rename Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952000676745482?= X-GMAIL-MSGID: =?utf-8?q?1747952000676745482?= In some cases we can be in deadlock because we tried to lock the same dir. Signed-off-by: Konstantin Komarov --- fs/ntfs3/namei.c | 4 ++++ fs/ntfs3/ntfs_fs.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 1af02d4f6b4d..13d6acc0747f 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -305,6 +305,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir, ni_lock_dir(dir_ni); ni_lock(ni); + if (dir_ni != new_dir_ni) + ni_lock_dir2(new_dir_ni); is_bad = false; err = ni_rename(dir_ni, new_dir_ni, ni, de, new_de, &is_bad); @@ -328,6 +330,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir, ntfs_sync_inode(inode); } + if (dir_ni != new_dir_ni) + ni_unlock(new_dir_ni); ni_unlock(ni); ni_unlock(dir_ni); out: diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index c45a411f82f6..5fad93a2c3fd 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -333,6 +333,7 @@ enum ntfs_inode_mutex_lock_class { NTFS_INODE_MUTEX_REPARSE, NTFS_INODE_MUTEX_NORMAL, NTFS_INODE_MUTEX_PARENT, + NTFS_INODE_MUTEX_PARENT2, }; /* @@ -1119,6 +1120,11 @@ static inline void ni_lock_dir(struct ntfs_inode *ni) mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT); } +static inline void ni_lock_dir2(struct ntfs_inode *ni) +{ + mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT2); +} + static inline void ni_unlock(struct ntfs_inode *ni) { mutex_unlock(&ni->ni_lock); From patchwork Fri Oct 28 17:04:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp944288wru; Fri, 28 Oct 2022 10:09:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4e43gSdGlbDzVVXMSc2O83Fg5ykK0p6j7aM2oQmN0Qo/1ZXblfs3A+q5+L6Kahg2N5dmLM X-Received: by 2002:a17:907:3f98:b0:7ad:8bc6:4cee with SMTP id hr24-20020a1709073f9800b007ad8bc64ceemr338061ejc.328.1666976944095; Fri, 28 Oct 2022 10:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976944; cv=none; d=google.com; s=arc-20160816; b=IZhmvfB66bnMG+R9p+p/bu2tAj6cwa/LpUZD7+2AzjkbmPz/vYGA4BugF64O+e/4jh pwPttYOYFDqy5Uy+ZweEd5BeSx+u6fDJp3nfBaaQ1iOFa3gvuG43tffT5VG5M/a+KbhL 3L9MDJKHE8oCA50kCzRN4ORQpGyjC+100BHTl57IqaT/cO0t0LDmI0cNBqUZKLKDZrC4 17yXW3ml9hHYYROnvNdv+yEwLNPswxQpQCHYlCEtbDEiWtdcB6Nt12Kkl3DIQWZLYz4z 5bem+fKleH5P5iUew6ewrDxkpwqfZRp27FjSvYk6QWWq5jBSCFGyoWuhqlnAvE0JsMEt K33Q== 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=jh6TmRNujxdGyXcLGIP5CgKNVwl50ZTAY12V/CuhgaM=; b=mvC8uj1bhgUm7j/Yio/me96D7BgTqekFq/6SMS6UlaYdZVqeXEqsqY0kwSCgqSmmg7 BET2fQ0FlTZZ0LBnKyKUd8Tc9GfAIgtaZnktZCTlOqtvargBeKmwCwC6V0dDVeff5lsV sp6v99ewndhT8Ua8KGy90BvJjcHBEg6ekztEHHR5/ECdbFxVD28h1M3eGT4NBlwMuYKu gsHfV9c1TnGjpQy853MtHGGpyDQS6YOnptlbuknoOJEOInoqTtJrJvIeU3SFB33tRcUk COaAPpuE2RsamYbkpYTltgBn371SjNcwBRN0qFItVWsYjXwxAftXY9vUQmRJb9D7uVKg H6GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=rMsB6p3M; 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 hq30-20020a1709073f1e00b0078df40b4300si3447523ejc.53.2022.10.28.10.08.40; Fri, 28 Oct 2022 10:09:04 -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=rMsB6p3M; 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 S230523AbiJ1RHH (ORCPT + 99 others); Fri, 28 Oct 2022 13:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbiJ1RGn (ORCPT ); Fri, 28 Oct 2022 13:06:43 -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 6A4653057C; Fri, 28 Oct 2022 10:04:56 -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 93084218D; Fri, 28 Oct 2022 17:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976535; bh=jh6TmRNujxdGyXcLGIP5CgKNVwl50ZTAY12V/CuhgaM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=rMsB6p3Mx7e9njRaCFp11e2gPAfFd0+9aH+JvJF3+hlE5fxowj+xFwj+MY6ZPOEDD ouau4on/yVxu2+kGt7CUg3SRwELHHZB7pz9NL+PT9+oj1RZTGFfiAEoK4xMk4pbW96 zotrhs8XsnHxgL7pft490w8f227Er6UL42mrSuUs= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:04:54 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:04:54 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 07/14] fs/ntfs3: Restore correct state after ENOSPC in attr_data_get_block Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952015909441785?= X-GMAIL-MSGID: =?utf-8?q?1747952015909441785?= Added new function ntfs_check_for_free_space. Added undo mechanism in attr_data_get_block. Fixes xfstest generic/083 Signed-off-by: Konstantin Komarov --- fs/ntfs3/attrib.c | 141 +++++++++++++++++++++++++++++---------------- fs/ntfs3/fsntfs.c | 33 +++++++++++ fs/ntfs3/ntfs_fs.h | 1 + 3 files changed, 125 insertions(+), 50 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 91ea73e6f4fe..5e6bafb10f42 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -891,8 +891,10 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, struct ATTR_LIST_ENTRY *le, *le_b; struct mft_inode *mi, *mi_b; CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end, vcn0, alen; + CLST alloc, evcn; unsigned fr; - u64 total_size; + u64 total_size, total_size0; + int step = 0; if (new) *new = false; @@ -932,7 +934,12 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, asize = le64_to_cpu(attr_b->nres.alloc_size) >> cluster_bits; if (vcn >= asize) { - err = -EINVAL; + if (new) { + err = -EINVAL; + } else { + *len = 1; + *lcn = SPARSE_LCN; + } goto out; } @@ -1036,10 +1043,12 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, if (err) goto out; *new = true; + step = 1; end = vcn + alen; - total_size = le64_to_cpu(attr_b->nres.total_size) + - ((u64)alen << cluster_bits); + /* Save 'total_size0' to restore if error. */ + total_size0 = le64_to_cpu(attr_b->nres.total_size); + total_size = total_size0 + ((u64)alen << cluster_bits); if (vcn != vcn0) { if (!run_lookup_entry(run, vcn0, lcn, len, NULL)) { @@ -1081,7 +1090,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, if (!ni->attr_list.size) { err = ni_create_attr_list(ni); if (err) - goto out; + goto undo1; /* Layout of records is changed. */ le_b = NULL; attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL, @@ -1098,67 +1107,83 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, } } + /* + * The code below may require additional cluster (to extend attribute list) + * and / or one MFT record + * It is too complex to undo operations if -ENOSPC occurs deep inside + * in 'ni_insert_nonresident'. + * Return in advance -ENOSPC here if there are no free cluster and no free MFT. + */ + if (!ntfs_check_for_free_space(sbi, 1, 1)) { + /* Undo step 1. */ + err = -ENOSPC; + goto undo1; + } + + step = 2; svcn = evcn1; /* Estimate next attribute. */ attr = ni_find_attr(ni, attr, &le, ATTR_DATA, NULL, 0, &svcn, &mi); - if (attr) { - CLST alloc = bytes_to_cluster( - sbi, le64_to_cpu(attr_b->nres.alloc_size)); - CLST evcn = le64_to_cpu(attr->nres.evcn); - - if (end < next_svcn) - end = next_svcn; - while (end > evcn) { - /* Remove segment [svcn : evcn). */ - mi_remove_attr(NULL, mi, attr); - - if (!al_remove_le(ni, le)) { - err = -EINVAL; - goto out; - } + if (!attr) { + /* Insert new attribute segment. */ + goto ins_ext; + } - if (evcn + 1 >= alloc) { - /* Last attribute segment. */ - evcn1 = evcn + 1; - goto ins_ext; - } + /* Try to update existed attribute segment. */ + alloc = bytes_to_cluster(sbi, le64_to_cpu(attr_b->nres.alloc_size)); + evcn = le64_to_cpu(attr->nres.evcn); - if (ni_load_mi(ni, le, &mi)) { - attr = NULL; - goto out; - } + if (end < next_svcn) + end = next_svcn; + while (end > evcn) { + /* Remove segment [svcn : evcn). */ + mi_remove_attr(NULL, mi, attr); - attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0, - &le->id); - if (!attr) { - err = -EINVAL; - goto out; - } - svcn = le64_to_cpu(attr->nres.svcn); - evcn = le64_to_cpu(attr->nres.evcn); + if (!al_remove_le(ni, le)) { + err = -EINVAL; + goto out; } - if (end < svcn) - end = svcn; + if (evcn + 1 >= alloc) { + /* Last attribute segment. */ + evcn1 = evcn + 1; + goto ins_ext; + } - err = attr_load_runs(attr, ni, run, &end); - if (err) + if (ni_load_mi(ni, le, &mi)) { + attr = NULL; goto out; + } - evcn1 = evcn + 1; - attr->nres.svcn = cpu_to_le64(next_svcn); - err = mi_pack_runs(mi, attr, run, evcn1 - next_svcn); - if (err) + attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL, 0, &le->id); + if (!attr) { + err = -EINVAL; goto out; + } + svcn = le64_to_cpu(attr->nres.svcn); + evcn = le64_to_cpu(attr->nres.evcn); + } - le->vcn = cpu_to_le64(next_svcn); - ni->attr_list.dirty = true; - mi->dirty = true; + if (end < svcn) + end = svcn; + + err = attr_load_runs(attr, ni, run, &end); + if (err) + goto out; + + evcn1 = evcn + 1; + attr->nres.svcn = cpu_to_le64(next_svcn); + err = mi_pack_runs(mi, attr, run, evcn1 - next_svcn); + if (err) + goto out; + + le->vcn = cpu_to_le64(next_svcn); + ni->attr_list.dirty = true; + mi->dirty = true; + next_svcn = le64_to_cpu(attr->nres.evcn) + 1; - next_svcn = le64_to_cpu(attr->nres.evcn) + 1; - } ins_ext: if (evcn1 > next_svcn) { err = ni_insert_nonresident(ni, ATTR_DATA, NULL, 0, run, @@ -1170,10 +1195,26 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, ok: run_truncate_around(run, vcn); out: + if (err && step > 1) { + /* Too complex to restore. */ + _ntfs_bad_inode(&ni->vfs_inode); + } up_write(&ni->file.run_lock); ni_unlock(ni); return err; + +undo1: + /* Undo step1. */ + attr_b->nres.total_size = cpu_to_le64(total_size0); + inode_set_bytes(&ni->vfs_inode, total_size0); + + if (run_deallocate_ex(sbi, run, vcn, alen, NULL, false) || + !run_add_entry(run, vcn, SPARSE_LCN, alen, false) || + mi_pack_runs(mi, attr, run, max(end, evcn1) - svcn)) { + _ntfs_bad_inode(&ni->vfs_inode); + } + goto out; } int attr_data_read_resident(struct ntfs_inode *ni, struct page *page) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 3fe2de74eeaf..b56ffb4951cc 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -419,6 +419,39 @@ int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, return err; } +/* + * ntfs_check_for_free_space + * + * Check if it is possible to allocate 'clen' clusters and 'mlen' Mft records + */ +bool ntfs_check_for_free_space(struct ntfs_sb_info *sbi, CLST clen, CLST mlen) +{ + size_t free, zlen, avail; + struct wnd_bitmap *wnd; + + wnd = &sbi->used.bitmap; + down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); + free = wnd_zeroes(wnd); + zlen = wnd_zone_len(wnd); + up_read(&wnd->rw_lock); + + if (free < zlen + clen) + return false; + + avail = free - (zlen + clen); + + wnd = &sbi->mft.bitmap; + down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_MFT); + free = wnd_zeroes(wnd); + zlen = wnd_zone_len(wnd); + up_read(&wnd->rw_lock); + + if (free >= zlen + mlen) + return true; + + return avail >= bytes_to_cluster(sbi, mlen << sbi->record_bits); +} + /* * ntfs_extend_mft - Allocate additional MFT records. * diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 5fad93a2c3fd..d73d1c837ba7 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -587,6 +587,7 @@ int ntfs_loadlog_and_replay(struct ntfs_inode *ni, struct ntfs_sb_info *sbi); int ntfs_look_for_free_space(struct ntfs_sb_info *sbi, CLST lcn, CLST len, CLST *new_lcn, CLST *new_len, enum ALLOCATE_OPT opt); +bool ntfs_check_for_free_space(struct ntfs_sb_info *sbi, CLST clen, CLST mlen); int ntfs_look_free_mft(struct ntfs_sb_info *sbi, CLST *rno, bool mft, struct ntfs_inode *ni, struct mft_inode **mi); void ntfs_mark_rec_free(struct ntfs_sb_info *sbi, CLST rno, bool is_mft); From patchwork Fri Oct 28 17:05:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp944495wru; Fri, 28 Oct 2022 10:09:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VZbOIhtWizU4Ud0cyOG8QmgWKfFo1yz4NZ4VrUi2+jwLkc4rh4YQNd2SGBGWv8Ujn19di X-Received: by 2002:a17:907:724d:b0:78d:acf4:4c57 with SMTP id ds13-20020a170907724d00b0078dacf44c57mr316679ejc.516.1666976970623; Fri, 28 Oct 2022 10:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976970; cv=none; d=google.com; s=arc-20160816; b=GBdGtdr5cT0FDgRBKi5vy+Xt9fuphoyIfiNMnXhqxzTir+nhx0ukKckg6Z56Xm9OjT OvbdtEUxlsBl+chKEFnPMxdf6tjTEJBNDKYh6pP65rmtHdLLApS353cPYHPQ9G8dpe0Q PMzXC5wY/yNlvDvezQGBCfi3SueJmYKgeC70EszO6jbi2RhakDK7FHC5v1Wk96ln+lii z8knvd0EgjUnzBcO7j7pOsssbe8RYsxWjO9rJiSFeOtdjMHJOkNgR8KFdx+AV8pA6I7x xt7Rdw45AABNvr7FTXW/aWqbc+ubW1zZkNn+0i4sQJvPIRxh0b5U/tlvhweZNqtnvQki WZQw== 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=Z1wJrT5mwfguS7h+6tsChzRtdrFWjJ5h0upJpKVRuVk=; b=jMHBTj22mNKQrzulN4Tv4RvFZPv5aF3e+EWlcwC52zx72SlyWPmsXt/kjGEChilUOS oviZGwLFljnvTNuTJXtlHhYAiGThWrSbuH8JobkXQtnDI9fUda6qFBi177bjJ2CZ+Ihe VmuMw5AdVbpLYcx2EH9rdPAK9OnWxmX+m7EspayG6Kto5NMvzPnRV/FYDrh/xbjyL/ra tjc7+RVjCtOi0ZhIM5iWcvlA775iszHaY6RbycU3wMkgjGYFxYrRT7ZEq52ubjA/fOZV apqqgfGtVCu067NWY/pY/2L9xH0LdB/6DdRGpSJ8qbmksBJBz4TGisA1ibRv5Obskno+ NnaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ap6Jd6Il; dkim=pass header.i=@paragon-software.com header.s=mail header.b="Od8/scn9"; 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 l3-20020a170907914300b0078de536a3cdsi2257277ejs.119.2022.10.28.10.09.06; Fri, 28 Oct 2022 10:09:30 -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=ap6Jd6Il; dkim=pass header.i=@paragon-software.com header.s=mail header.b="Od8/scn9"; 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 S230486AbiJ1RHz (ORCPT + 99 others); Fri, 28 Oct 2022 13:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbiJ1RHf (ORCPT ); Fri, 28 Oct 2022 13:07:35 -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 57C6089916; Fri, 28 Oct 2022 10:05:23 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 9F7C5218D; Fri, 28 Oct 2022 17:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976561; bh=Z1wJrT5mwfguS7h+6tsChzRtdrFWjJ5h0upJpKVRuVk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ap6Jd6Il508YZcM9lbiU4LL2kgEi4UhNsNWfCnwz82iAyHSOTNCS15nO6A1HsqqAh T3UKIuf6LKcjsfIE0WH7E/wixWbAPAbeuKLxMXFtdYEqwfG93+cA/R4a11d4NWKeeX edS2NmHWt3Xugulc3YadJcy5AWyWed3mdVCIp+3A= 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 9D6C0DD; Fri, 28 Oct 2022 17:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976720; bh=Z1wJrT5mwfguS7h+6tsChzRtdrFWjJ5h0upJpKVRuVk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Od8/scn9IvuypjfeFrrovmpLjKo9xf74MXtp5mvONypWGUSwprXwoK1UXw3c3YuCk tNECaWd3SGEm8ey2KObVffO0Hctm1mtjqsdBqa6eM0dETSKqGRVN4qratXSr1csDmZ pBIOvXCGCvm2j/GxjuAdWFrVr447zC7AsIjICX5o= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:05:20 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:05:20 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 08/14] fs/ntfs3: Correct ntfs_check_for_free_space Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952043807545180?= X-GMAIL-MSGID: =?utf-8?q?1747952043807545180?= zlen in some cases was bigger than correct value. Signed-off-by: Konstantin Komarov --- fs/ntfs3/fsntfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index b56ffb4951cc..e5a1f4df0397 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -432,7 +432,7 @@ bool ntfs_check_for_free_space(struct ntfs_sb_info *sbi, CLST clen, CLST mlen) wnd = &sbi->used.bitmap; down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); free = wnd_zeroes(wnd); - zlen = wnd_zone_len(wnd); + zlen = min_t(size_t, NTFS_MIN_MFT_ZONE, wnd_zone_len(wnd)); up_read(&wnd->rw_lock); if (free < zlen + clen) From patchwork Fri Oct 28 17:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp944889wru; Fri, 28 Oct 2022 10:10:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ondjKRzoNe9kjT/GwmxH5wfAURItwECl0r0KawuZT9unmIrVdj3Xvvz+1BAcT9ZUfRqS3 X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr419604edb.123.1666977018261; Fri, 28 Oct 2022 10:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977018; cv=none; d=google.com; s=arc-20160816; b=JdwEVoCXv73bafo4KAcB0Ntx9CT7TIpbZZanRTdnidYwLyskJ41SfGA2CwyqJ/S+1N h3Usx2DVg79D4vCZE0FjTQeaIgzCkMIRYcZ04K+vuQzbqQx5dGyCYrddjnOgbi5vW6wb Nlkf7C03tth0c6zcYPz7Ym0kdHWiJU1QIZq+lGTkdUyNWUS1y/vYcFCKjPHw1naIiAW+ OCXpxpgngcZWiq1gOoo4kiloWxrFjOvYZy+szlNTNAAYicGKRg50uEBJC3kPzhBVCddl AsTrWMnhsOHxzljsuGcuXQerxAxIdn+kzoo9bhCOLO9cIeg/XxnahIX3DMjy3IUgq0ML 1TKA== 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=1RIl0qzpJnMi+2+dH4z4jpT23+ZMHz1t7tDXrl1ZrQc=; b=JLUQ4CGgOYFUmydC9suQFoSxndICr6IKodZruElvPESJ4m4qSut6honXj3ZcpopcMN Y+b4fFtAtEc3v/iG3XkiW37tX+bMls5MvCVjzdGX0XkxP4y194iFQ9cg2w8c8J0hBdbt sSHjI2U7Lq+92HNPVLLw/ISjWq9HgDHPA3a63TEN9bN+tJFxkqpP/eSaNCzmAOD50rUI gj/0E1rLjFg/FwY319AeTS2vCHTNIbcsFnKv++Vowue9NuiGQXA0jRHCb7Lq1kNr0hRS 4DQCtgeFcugefY5AmB0izFyVN0yPiwxweJxgQr5o1xF9sO0eIB0XRJJ6kkwFJC+jKKZ7 cyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=c4hqfpf7; 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 nc21-20020a1709071c1500b0078b6559a610si5450507ejc.12.2022.10.28.10.09.54; Fri, 28 Oct 2022 10:10: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=c4hqfpf7; 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 S231326AbiJ1RIx (ORCPT + 99 others); Fri, 28 Oct 2022 13:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbiJ1RIZ (ORCPT ); Fri, 28 Oct 2022 13:08:25 -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 20973F17; Fri, 28 Oct 2022 10:06:17 -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 962E8218D; Fri, 28 Oct 2022 17:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976597; bh=1RIl0qzpJnMi+2+dH4z4jpT23+ZMHz1t7tDXrl1ZrQc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=c4hqfpf7yWXHSaSXqqknbXuh2DNay4FC/rErSJ4GLONniPXf7esj4AttHTLVjYZwE HoE3ksVGC8//FeF6kjVdjRqUpfxodlUe0cA+QCCpUbEF11OSGKDygVdhzVfZumeSMy 65QlbTXMQF2Mb0dYNjAH09f9aClNN+vFgJtD4uCg= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:05:56 +0300 Message-ID: <0ec81044-062c-29e0-c081-dff9484f0368@paragon-software.com> Date: Fri, 28 Oct 2022 20:05:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 09/14] fs/ntfs3: Check fields while reading Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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_FILL_THIS_FORM_SHORT 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?1747952093807785659?= X-GMAIL-MSGID: =?utf-8?q?1747952093807785659?= Added new functions index_hdr_check and index_buf_check. Now we check all stuff for correctness while reading from disk. Also fixed bug with stale nfs data. Reported-by: van fantasy Signed-off-by: Konstantin Komarov --- fs/ntfs3/index.c | 84 ++++++++++++++++++++++++++++++---- fs/ntfs3/inode.c | 18 ++++---- fs/ntfs3/ntfs_fs.h | 4 +- fs/ntfs3/run.c | 7 ++- fs/ntfs3/xattr.c | 109 +++++++++++++++++++++++++++++---------------- 5 files changed, 164 insertions(+), 58 deletions(-) diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 35369ae5c438..51ab75954640 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -605,11 +605,58 @@ static const struct NTFS_DE *hdr_insert_head(struct INDEX_HDR *hdr, return e; } +/* + * index_hdr_check + * + * return true if INDEX_HDR is valid + */ +static bool index_hdr_check(const struct INDEX_HDR *hdr, u32 bytes) +{ + u32 end = le32_to_cpu(hdr->used); + u32 tot = le32_to_cpu(hdr->total); + u32 off = le32_to_cpu(hdr->de_off); + + if (!IS_ALIGNED(off, 8) || tot > bytes || end > tot || + off + sizeof(struct NTFS_DE) > end) { + /* incorrect index buffer. */ + return false; + } + + return true; +} + +/* + * index_buf_check + * + * return true if INDEX_BUFFER seems is valid + */ +static bool index_buf_check(const struct INDEX_BUFFER *ib, u32 bytes, + const CLST *vbn) +{ + const struct NTFS_RECORD_HEADER *rhdr = &ib->rhdr; + u16 fo = le16_to_cpu(rhdr->fix_off); + u16 fn = le16_to_cpu(rhdr->fix_num); + + if (bytes <= offsetof(struct INDEX_BUFFER, ihdr) || + rhdr->sign != NTFS_INDX_SIGNATURE || + fo < sizeof(struct INDEX_BUFFER) + /* Check index buffer vbn. */ + || (vbn && *vbn != le64_to_cpu(ib->vbn)) || (fo % sizeof(short)) || + fo + fn * sizeof(short) >= bytes || + fn != ((bytes >> SECTOR_SHIFT) + 1)) { + /* incorrect index buffer. */ + return false; + } + + return index_hdr_check(&ib->ihdr, + bytes - offsetof(struct INDEX_BUFFER, ihdr)); +} + void fnd_clear(struct ntfs_fnd *fnd) { int i; - for (i = 0; i < fnd->level; i++) { + for (i = fnd->level - 1; i >= 0; i--) { struct indx_node *n = fnd->nodes[i]; if (!n) @@ -819,9 +866,16 @@ int indx_init(struct ntfs_index *indx, struct ntfs_sb_info *sbi, u32 t32; const struct INDEX_ROOT *root = resident_data(attr); + t32 = le32_to_cpu(attr->res.data_size); + if (t32 <= offsetof(struct INDEX_ROOT, ihdr) || + !index_hdr_check(&root->ihdr, + t32 - offsetof(struct INDEX_ROOT, ihdr))) { + goto out; + } + /* Check root fields. */ if (!root->index_block_clst) - return -EINVAL; + goto out; indx->type = type; indx->idx2vbn_bits = __ffs(root->index_block_clst); @@ -833,19 +887,19 @@ int indx_init(struct ntfs_index *indx, struct ntfs_sb_info *sbi, if (t32 < sbi->cluster_size) { /* Index record is smaller than a cluster, use 512 blocks. */ if (t32 != root->index_block_clst * SECTOR_SIZE) - return -EINVAL; + goto out; /* Check alignment to a cluster. */ if ((sbi->cluster_size >> SECTOR_SHIFT) & (root->index_block_clst - 1)) { - return -EINVAL; + goto out; } indx->vbn2vbo_bits = SECTOR_SHIFT; } else { /* Index record must be a multiple of cluster size. */ if (t32 != root->index_block_clst << sbi->cluster_bits) - return -EINVAL; + goto out; indx->vbn2vbo_bits = sbi->cluster_bits; } @@ -853,7 +907,14 @@ int indx_init(struct ntfs_index *indx, struct ntfs_sb_info *sbi, init_rwsem(&indx->run_lock); indx->cmp = get_cmp_func(root); - return indx->cmp ? 0 : -EINVAL; + if (!indx->cmp) + goto out; + + return 0; + +out: + ntfs_set_state(sbi, NTFS_DIRTY_DIRTY); + return -EINVAL; } static struct indx_node *indx_new(struct ntfs_index *indx, @@ -1011,6 +1072,13 @@ int indx_read(struct ntfs_index *indx, struct ntfs_inode *ni, CLST vbn, goto out; ok: + if (!index_buf_check(ib, bytes, &vbn)) { + ntfs_inode_err(&ni->vfs_inode, "directory corrupted"); + ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR); + err = -EINVAL; + goto out; + } + if (err == -E_NTFS_FIXUP) { ntfs_write_bh(ni->mi.sbi, &ib->rhdr, &in->nb, 0); err = 0; @@ -1601,9 +1669,9 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni, if (err) { /* Restore root. */ - if (mi_resize_attr(mi, attr, -ds_root)) + if (mi_resize_attr(mi, attr, -ds_root)) { memcpy(attr, a_root, asize); - else { + } else { /* Bug? */ ntfs_set_state(sbi, NTFS_DIRTY_ERROR); } diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 78ec3e6bbf67..719cf6fbb5ed 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -81,7 +81,7 @@ static struct inode *ntfs_read_mft(struct inode *inode, le16_to_cpu(ref->seq), le16_to_cpu(rec->seq)); goto out; } else if (!is_rec_inuse(rec)) { - err = -EINVAL; + err = -ESTALE; ntfs_err(sb, "Inode r=%x is not in use!", (u32)ino); goto out; } @@ -92,8 +92,10 @@ static struct inode *ntfs_read_mft(struct inode *inode, goto out; } - if (!is_rec_base(rec)) - goto Ok; + if (!is_rec_base(rec)) { + err = -EINVAL; + goto out; + } /* Record should contain $I30 root. */ is_dir = rec->flags & RECORD_FLAG_DIR; @@ -465,7 +467,6 @@ static struct inode *ntfs_read_mft(struct inode *inode, inode->i_flags |= S_NOSEC; } -Ok: if (ino == MFT_REC_MFT && !sb->s_root) sbi->mft.ni = NULL; @@ -519,6 +520,9 @@ struct inode *ntfs_iget5(struct super_block *sb, const struct MFT_REF *ref, _ntfs_bad_inode(inode); } + if (IS_ERR(inode) && name) + ntfs_set_state(sb->s_fs_info, NTFS_DIRTY_ERROR); + return inode; } @@ -1652,10 +1656,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, ntfs_remove_reparse(sbi, IO_REPARSE_TAG_SYMLINK, &new_de->ref); out5: - if (S_ISDIR(mode) || run_is_empty(&ni->file.run)) - goto out4; - - run_deallocate(sbi, &ni->file.run, false); + if (!S_ISDIR(mode)) + run_deallocate(sbi, &ni->file.run, false); out4: clear_rec_inuse(rec); diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index d73d1c837ba7..c9b8a6f1ba0b 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -795,12 +795,12 @@ int run_pack(const struct runs_tree *run, CLST svcn, CLST len, u8 *run_buf, u32 run_buf_size, CLST *packed_vcns); int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, CLST svcn, CLST evcn, CLST vcn, const u8 *run_buf, - u32 run_buf_size); + int run_buf_size); #ifdef NTFS3_CHECK_FREE_CLST int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, CLST svcn, CLST evcn, CLST vcn, const u8 *run_buf, - u32 run_buf_size); + int run_buf_size); #else #define run_unpack_ex run_unpack #endif diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c index aaaa0d3d35a2..12d8682f33b5 100644 --- a/fs/ntfs3/run.c +++ b/fs/ntfs3/run.c @@ -919,12 +919,15 @@ int run_pack(const struct runs_tree *run, CLST svcn, CLST len, u8 *run_buf, */ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, CLST svcn, CLST evcn, CLST vcn, const u8 *run_buf, - u32 run_buf_size) + int run_buf_size) { u64 prev_lcn, vcn64, lcn, next_vcn; const u8 *run_last, *run_0; bool is_mft = ino == MFT_REC_MFT; + if (run_buf_size < 0) + return -EINVAL; + /* Check for empty. */ if (evcn + 1 == svcn) return 0; @@ -1046,7 +1049,7 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, */ int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, CLST svcn, CLST evcn, CLST vcn, const u8 *run_buf, - u32 run_buf_size) + int run_buf_size) { int ret, err; CLST next_vcn, lcn, len; diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index aeee5fb12092..385c50831a8d 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -42,28 +42,26 @@ static inline size_t packed_ea_size(const struct EA_FULL *ea) * Assume there is at least one xattr in the list. */ static inline bool find_ea(const struct EA_FULL *ea_all, u32 bytes, - const char *name, u8 name_len, u32 *off) + const char *name, u8 name_len, u32 *off, u32 *ea_sz) { - *off = 0; + u32 ea_size; - if (!ea_all || !bytes) + *off = 0; + if (!ea_all) return false; - for (;;) { + for (; *off < bytes; *off += ea_size) { const struct EA_FULL *ea = Add2Ptr(ea_all, *off); - u32 next_off = *off + unpacked_ea_size(ea); - - if (next_off > bytes) - return false; - + ea_size = unpacked_ea_size(ea); if (ea->name_len == name_len && - !memcmp(ea->name, name, name_len)) + !memcmp(ea->name, name, name_len)) { + if (ea_sz) + *ea_sz = ea_size; return true; - - *off = next_off; - if (next_off >= bytes) - return false; + } } + + return false; } /* @@ -74,12 +72,12 @@ static inline bool find_ea(const struct EA_FULL *ea_all, u32 bytes, static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, size_t add_bytes, const struct EA_INFO **info) { - int err; + int err = -EINVAL; struct ntfs_sb_info *sbi = ni->mi.sbi; struct ATTR_LIST_ENTRY *le = NULL; struct ATTRIB *attr_info, *attr_ea; void *ea_p; - u32 size; + u32 size, off, ea_size; static_assert(le32_to_cpu(ATTR_EA_INFO) < le32_to_cpu(ATTR_EA)); @@ -96,24 +94,31 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, *info = resident_data_ex(attr_info, sizeof(struct EA_INFO)); if (!*info) - return -EINVAL; + goto out; /* Check Ea limit. */ size = le32_to_cpu((*info)->size); - if (size > sbi->ea_max_size) - return -EFBIG; + if (size > sbi->ea_max_size) { + err = -EFBIG; + goto out; + } + + if (attr_size(attr_ea) > sbi->ea_max_size) { + err = -EFBIG; + goto out; + } - if (attr_size(attr_ea) > sbi->ea_max_size) - return -EFBIG; + if (!size) { + /* EA info persists, but xattr is empty. Looks like EA problem. */ + goto out; + } /* Allocate memory for packed Ea. */ ea_p = kmalloc(size_add(size, add_bytes), GFP_NOFS); if (!ea_p) return -ENOMEM; - if (!size) { - /* EA info persists, but xattr is empty. Looks like EA problem. */ - } else if (attr_ea->non_res) { + if (attr_ea->non_res) { struct runs_tree run; run_init(&run); @@ -124,24 +129,52 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, run_close(&run); if (err) - goto out; + goto out1; } else { void *p = resident_data_ex(attr_ea, size); - if (!p) { - err = -EINVAL; - goto out; - } + if (!p) + goto out1; memcpy(ea_p, p, size); } memset(Add2Ptr(ea_p, size), 0, add_bytes); + + /* Check all attributes for consistency. */ + for (off = 0; off < size; off += ea_size) { + const struct EA_FULL *ef = Add2Ptr(ea_p, off); + u32 bytes = size - off; + + /* Check if we can use field ea->size. */ + if (bytes < sizeof(ef->size)) + goto out1; + + if (ef->size) { + ea_size = le32_to_cpu(ef->size); + if (ea_size > bytes) + goto out1; + continue; + } + + /* Check if we can use fields ef->name_len and ef->elength. */ + if (bytes < offsetof(struct EA_FULL, name)) + goto out1; + + ea_size = ALIGN(struct_size(ef, name, + 1 + ef->name_len + + le16_to_cpu(ef->elength)), + 4); + if (ea_size > bytes) + goto out1; + } + *ea = ea_p; return 0; -out: +out1: kfree(ea_p); - *ea = NULL; +out: + ntfs_set_state(sbi, NTFS_DIRTY_DIRTY); return err; } @@ -163,6 +196,7 @@ static ssize_t ntfs_list_ea(struct ntfs_inode *ni, char *buffer, const struct EA_FULL *ea; u32 off, size; int err; + int ea_size; size_t ret; err = ntfs_read_ea(ni, &ea_all, 0, &info); @@ -175,8 +209,9 @@ 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 < size; off += unpacked_ea_size(ea)) { + for (ret = 0, off = 0; off < size; off += ea_size) { ea = Add2Ptr(ea_all, off); + ea_size = unpacked_ea_size(ea); if (buffer) { if (ret + ea->name_len + 1 > bytes_per_buffer) { @@ -227,7 +262,8 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len, goto out; /* Enumerate all xattrs. */ - if (!find_ea(ea_all, le32_to_cpu(info->size), name, name_len, &off)) { + if (!find_ea(ea_all, le32_to_cpu(info->size), name, name_len, &off, + NULL)) { err = -ENODATA; goto out; } @@ -269,7 +305,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, struct EA_FULL *new_ea; struct EA_FULL *ea_all = NULL; size_t add, new_pack; - u32 off, size; + u32 off, size, ea_sz; __le16 size_pack; struct ATTRIB *attr; struct ATTR_LIST_ENTRY *le; @@ -304,9 +340,8 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, size_pack = ea_info.size_pack; } - if (info && find_ea(ea_all, size, name, name_len, &off)) { + if (info && find_ea(ea_all, size, name, name_len, &off, &ea_sz)) { struct EA_FULL *ea; - size_t ea_sz; if (flags & XATTR_CREATE) { err = -EEXIST; @@ -329,8 +364,6 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, if (ea->flags & FILE_NEED_EA) le16_add_cpu(&ea_info.count, -1); - ea_sz = unpacked_ea_size(ea); - le16_add_cpu(&ea_info.size_pack, 0 - packed_ea_size(ea)); memmove(ea, Add2Ptr(ea, ea_sz), size - off - ea_sz); From patchwork Fri Oct 28 17:06:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp944985wru; Fri, 28 Oct 2022 10:10:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KYNgVCtBHDxWso5pFXVC/mMzq1OrMTFaODTsvx53Iou9S2r3YIBom13WIoT5wgO3zLYY6 X-Received: by 2002:a17:906:9be6:b0:7ad:a73b:40c7 with SMTP id de38-20020a1709069be600b007ada73b40c7mr301566ejc.483.1666977028323; Fri, 28 Oct 2022 10:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977028; cv=none; d=google.com; s=arc-20160816; b=ZtJQdEnR9owcTgCv9lGOC7pN0Pw6yNo20+/6kVFIKNZI+HZE1D2g+qSmMWYg6PuPRX lae2C+pQtEECdUOS9xOG901Tc0EGhF03LETkcJK3Z5hhWTGhxRgB2nschPe2HyTt4PhY mQReySZa0P4DepjkuPpp0TsdyanSa/BM72WmGQ3MEL5Tp1koanGIkoe9ge2ZoxK3qket Ly5BhCJlKSxF7PjY/fA+lOFcXIcyPP1HMKjn6j3Q90PoKkKzOi2yZp9m/k+Im56dcF/9 tt+7hcYmaeyxdM+SJfowu8r9HrS+uF4Vy+FwSXmekRfvzlIlWKtqhAb0UEQ7lQaXW7U/ E0Qw== 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=j4ORUvqVhkK0F9A+1IIYdz9n48bqtuNM+OM62p7TIGk=; b=RnDEnOrmWgGKJIxl7muy1fQ/R9zNY+XYusk5djhKMGDR6F2WqmbmIgvHex2NYj+oGZ 7ZsHb0kgwSjkJwBY7jALrk//msDetbiBAyP2k6Zp602En7Ec+9LLW+YHLXhh1RLbnJc8 dppjoneqPIUvUnpU+MWLrQ5/pXDoM+fN2oLN0/XsABNfcKGyF6lVAtXSe+ompHNl1hNO akzUZeMd0f9v+pvW9+QTjX+/o/SofU5kgb0eugwIHJzHgr6mT6/KQexUX2Wdso58GSnH KAfNrLwj9f25MdOmD5y76QWY66m9PmJYm9rhreflUvPH22biwLt7xDGiUip79K3s1hU3 X36g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=FHK05avF; dkim=pass header.i=@paragon-software.com header.s=mail header.b=VKPh8fFO; 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 z36-20020a509e27000000b0045c0accb2b8si3544890ede.205.2022.10.28.10.10.04; Fri, 28 Oct 2022 10:10:28 -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=FHK05avF; dkim=pass header.i=@paragon-software.com header.s=mail header.b=VKPh8fFO; 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 S230315AbiJ1RJI (ORCPT + 99 others); Fri, 28 Oct 2022 13:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiJ1RIw (ORCPT ); Fri, 28 Oct 2022 13:08:52 -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 8243A237969; Fri, 28 Oct 2022 10:06: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 8EE1B2190; Fri, 28 Oct 2022 17:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976621; bh=j4ORUvqVhkK0F9A+1IIYdz9n48bqtuNM+OM62p7TIGk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=FHK05avF9oE6RAvXO72+smY9XzEcWpcd80DLIpUH4SCCjl7G27Y0tZBQqFrtZkUmC RhuYbADIpVVOD8nzqYHqHx0Rvo4TFH3lgBTZu5wnL/cVOSDBhm7ya6qud8Xjf14NBF l7oJOIH2e8iz+EPBGa5axGM1GAPkuk2x578Q1cpI= 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 8C4DEDD; Fri, 28 Oct 2022 17:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976780; bh=j4ORUvqVhkK0F9A+1IIYdz9n48bqtuNM+OM62p7TIGk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=VKPh8fFOP+7Fw3rPiiEKH9CCeDSs5ZvaGd1IiP8dtrS3+NZHgD3SeaduCWNeyrUWc cnMoDaHYeclz5Pr1PfDD2dQVKRZopW9/AujhVUa5PCSHs9AbAUnr/vxIUAe28TwW4r FzQBMAFo7+z/SHdkd4InHtmDmLbDuzxyVjxTdF1g= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:06:20 +0300 Message-ID: <2753fbab-c602-9bad-1f93-65c050461703@paragon-software.com> Date: Fri, 28 Oct 2022 20:06:20 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 10/14] fs/ntfs3: Fix incorrect if in ntfs_set_acl_ex Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952104229847453?= X-GMAIL-MSGID: =?utf-8?q?1747952104229847453?= We need to update ctime too with mode. Fixes xfstest generic/307 Signed-off-by: Konstantin Komarov --- fs/ntfs3/xattr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 385c50831a8d..bead9c3059ce 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -637,10 +637,9 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, err = 0; /* Removing non existed xattr. */ if (!err) { set_cached_acl(inode, type, acl); - if (inode->i_mode != mode) { - inode->i_mode = mode; - mark_inode_dirty(inode); - } + inode->i_mode = mode; + inode->i_ctime = current_time(inode); + mark_inode_dirty(inode); } out: From patchwork Fri Oct 28 17:06:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp945223wru; Fri, 28 Oct 2022 10:10:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eDdFdI0zIyVuWsVUU2B3gJ2JboH+gck/QLeoOW7v2WKyiVyJH9BIvwC6mYOwehIi0uIvk X-Received: by 2002:a17:906:9c83:b0:779:c14c:55e4 with SMTP id fj3-20020a1709069c8300b00779c14c55e4mr279082ejc.619.1666977057943; Fri, 28 Oct 2022 10:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977057; cv=none; d=google.com; s=arc-20160816; b=D5ijDXoLM7s4U1BbjdZTDhbmdwp11RUUPVoMSJ0Or7mD1vkKDLDfQWdHkFRSXZPJ9w novrf0evq18RFAEOy4UFuqJEVWbfdyQlNi2AyMpnvRywsaM6mFoMLdvI6ymS3AfOuGiI iLGnpe3caLkwvfkIErMmtQgU55pPOlPksBH3xY7eaYzHms1IxZP4m8LxTdLGYQBzsBe7 AEjd8nI45ENTjJtibSMpC5QT5/DYJ6GkDt6Sv4By1Smv5ZJ/mH/v4q7mCiXjxVC3xPT/ sGcB4dv8ruf0Ns1dkWXPlTDtkrfGmbmHnLbUgX+YvPP9CxSVq7/EaWMTly8uW7rtoqSV M+9Q== 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=vZQidD9CJW5D93E6fSX67v6fhJf0xZSsvUiQiK86ffE=; b=HccKQKV3xc1Xdze0VFGyQY4N8noSryqXLkXa/3FE0nGs5mU5M9kZR0mKyAi1DmJ1HM qNpTQ73YdENZPE+lah3GZ9+u1vBhbLczmvO3XCYIPRQ0/LooTZ+cJL5sx3vjqNeLYAfV G5Qt8JUgmH97d9m0YDlQ+Msa31C9Nfa5LyAS8hxZD7guGTrkSDjb0TF/enDYOU1RaDOx aRQrrUp/lNk2ma2LA7b/5F3gKcTgZlGejYb4Ar9McMQVYIgYqjvbheihy4xovRvIlWIg FnfhmbiTHwGI2vF/dkQcMOgpJDu6VvmuvzLI8MWNAStPFOQJl95I56Mi3Ws1oxKq+oKZ zsiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=NyNL3VpJ; 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 v13-20020a056402348d00b0045be16903d0si467440edc.310.2022.10.28.10.10.33; Fri, 28 Oct 2022 10:10: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=NyNL3VpJ; 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 S230490AbiJ1RJt (ORCPT + 99 others); Fri, 28 Oct 2022 13:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230520AbiJ1RJX (ORCPT ); Fri, 28 Oct 2022 13:09:23 -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 2A18E241B21; Fri, 28 Oct 2022 10:06:47 -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 0BFCD218D; Fri, 28 Oct 2022 17:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976647; bh=vZQidD9CJW5D93E6fSX67v6fhJf0xZSsvUiQiK86ffE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=NyNL3VpJEnie2japjXib21D1rz7EgtMMl+SJmVZwshFGqkdpFtAgcfd8tMb8LQZUQ 4qcv6UNy8SWyEe82+pWEh7MXoRQNh2aA/M04rlZAFkreYsidr7JDt+2E+CM7jLYiJb 8KyuqlN9w0Yaol8e+PniR11N2QOvm7V+VL2Otj6Y= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:06:45 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:06:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 11/14] fs/ntfs3: Use ALIGN kernel macro Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952135603695732?= X-GMAIL-MSGID: =?utf-8?q?1747952135603695732?= This way code will be more readable. Signed-off-by: Konstantin Komarov --- fs/ntfs3/fsntfs.c | 2 +- fs/ntfs3/ntfs.h | 1 - fs/ntfs3/ntfs_fs.h | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index e5a1f4df0397..1e01a3e8e01e 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -479,7 +479,7 @@ static int ntfs_extend_mft(struct ntfs_sb_info *sbi) struct ATTRIB *attr; struct wnd_bitmap *wnd = &sbi->mft.bitmap; - new_mft_total = (wnd->nbits + MFT_INCREASE_CHUNK + 127) & (CLST)~127; + new_mft_total = ALIGN(wnd->nbits + NTFS_MFT_INCREASE_STEP, 128); new_mft_bytes = (u64)new_mft_total << sbi->record_bits; /* Step 1: Resize $MFT::DATA. */ diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 9cc396b117bf..9f764bf4ed0a 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -84,7 +84,6 @@ typedef u32 CLST; #define COMPRESSION_UNIT 4 #define COMPRESS_MAX_CLUSTER 0x1000 -#define MFT_INCREASE_CHUNK 1024 enum RECORD_NUM { MFT_REC_MFT = 0, diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index c9b8a6f1ba0b..bc02cfb344f9 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -198,6 +198,8 @@ struct ntfs_index { /* Minimum MFT zone. */ #define NTFS_MIN_MFT_ZONE 100 +/* Step to increase the MFT. */ +#define NTFS_MFT_INCREASE_STEP 1024 /* Ntfs file system in-core superblock data. */ struct ntfs_sb_info { From patchwork Fri Oct 28 17:07:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp945418wru; Fri, 28 Oct 2022 10:11:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6DfIw3N1+Fh/eQtqgIvhYNQZNbs79kFa+PVVgZ4l1PE9v65bmjZ+y1GejsGXl9h7XOa30Q X-Received: by 2002:a17:906:ee89:b0:73d:70c5:1a4e with SMTP id wt9-20020a170906ee8900b0073d70c51a4emr275208ejb.683.1666977087475; Fri, 28 Oct 2022 10:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977087; cv=none; d=google.com; s=arc-20160816; b=u2q1EsN+aEob4lMBDLpt6urmVggdFbucBmEQCth8aJkMDc0dbhN9aQ1GsXGAotc5FP xH4WkEMMDqRQ/z4lpRovM7l0+dSR4UnXuKDO9EhfVMPKEo5OTXbURWuLgitEDMtj+bDL FkrMpWB2ywHP5hc09vsGFkFBj1r2CvyPYl00WVwAVoLcbaIz1krn4gOuZbiwjRJt12nO QbLe+3MnbVkIAd1isUjnWp5U+/lCTC0AxzKm9GXKGUvzD6ZdCZFv6eQQt4gsUvZ5DFKF MWmmJW8fDGlWxM5hkXO/DL4X2GYQtPpTgVISnZiUJ4fBgtYfjOpYEYjmwYub72gK7D7W y0Ow== 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=U5rbfGUDH6ccvvDNl8615tsqE6RiTSqFhdpj1nt8ic0=; b=wmxe9BKa8ZNAnrSc5TFZqvx7w+nJokUJnrF//h4CU2Ovr+r5wBry+lhxIMGQJ85ooS T2hSzN5Xm7aL2+AYL8PzYREih5uOXY5VdKzNRPiJnFhwTttHrYzTnROAdG1gFcJ6Jpwb Kki8cvvWVarHwgWiqcDGPv+6NxUbq3XVZSnukHfW+GbVgDVtC/c9cXvwPLwmpFXk09Z/ yGYqD5FVkc+CgKUt65lBahaweDLg08i3cmpIEAairdao00t1beU5U9gc8WgGlRMjMSvq iVNJ/uzSKYQ4aRIBtz/yu6NGHL6jbhjlogSlN8DVABIFHJEg10Z3Nlay4zifigmCSTpK /xXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=hwSGfoen; dkim=pass header.i=@paragon-software.com header.s=mail header.b=YE23VZEz; 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 c9-20020a05640227c900b00459528ef81bsi6335423ede.324.2022.10.28.10.11.04; Fri, 28 Oct 2022 10:11:27 -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=hwSGfoen; dkim=pass header.i=@paragon-software.com header.s=mail header.b=YE23VZEz; 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 S231362AbiJ1RKd (ORCPT + 99 others); Fri, 28 Oct 2022 13:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbiJ1RJx (ORCPT ); Fri, 28 Oct 2022 13:09:53 -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 1FF0C23AB70; Fri, 28 Oct 2022 10:07: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 470E5218D; Fri, 28 Oct 2022 17:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976683; bh=U5rbfGUDH6ccvvDNl8615tsqE6RiTSqFhdpj1nt8ic0=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=hwSGfoen1bMnhsSlVk8x6dEwrUSpuNPsLhvXJnARtw5MNCA1r1KWx5dao/d9v3eoK 3Vu0+WppGF6nw8xAtqoIFmKwUeTp4O6J0hWqj4kSYi6HnXd+awtcyeNNgCn3tlbZKA 1t3QcY0SwItky4YG4Lokvq28mmbaDSV/EgRIpuxc= 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 43FAADD; Fri, 28 Oct 2022 17:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976842; bh=U5rbfGUDH6ccvvDNl8615tsqE6RiTSqFhdpj1nt8ic0=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=YE23VZEzseXPeW66Goh/t49OwxklhqLY0j5wtbGtZJlmHCCVtuQILU9sJbZDgZGhe V/SolDCexSsbF+eOmm2OHKN394ShVLf+z5SdQP1IImgkDMogC/9hLKgi6dk6LjIZ2F hkSWbWe2tNdvhcDZnm+36N8X+jIZs0VEiOD0EAyM= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:07:21 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:07:21 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 12/14] fs/ntfs3: Fix wrong if in hdr_first_de Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952166163990855?= X-GMAIL-MSGID: =?utf-8?q?1747952166163990855?= We need to check used bytes instead of total. Signed-off-by: Konstantin Komarov --- fs/ntfs3/ntfs.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 9f764bf4ed0a..86ea1826d099 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -714,12 +714,13 @@ static inline struct NTFS_DE *hdr_first_de(const struct INDEX_HDR *hdr) { u32 de_off = le32_to_cpu(hdr->de_off); u32 used = le32_to_cpu(hdr->used); - struct NTFS_DE *e = Add2Ptr(hdr, de_off); + struct NTFS_DE *e; u16 esize; - if (de_off >= used || de_off >= le32_to_cpu(hdr->total)) + if (de_off >= used || de_off + sizeof(struct NTFS_DE) > used ) return NULL; + e = Add2Ptr(hdr, de_off); esize = le16_to_cpu(e->size); if (esize < sizeof(struct NTFS_DE) || de_off + esize > used) return NULL; From patchwork Fri Oct 28 17:07:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp945551wru; Fri, 28 Oct 2022 10:11:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wtB076tn+jeAJmzmbEgM8I+DF/iEvlZniUu1E4XYHf0AMAJc+FGF07tik9vX72mumf6CO X-Received: by 2002:a17:907:3181:b0:787:d81c:a6ad with SMTP id xe1-20020a170907318100b00787d81ca6admr277036ejb.769.1666977110998; Fri, 28 Oct 2022 10:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977110; cv=none; d=google.com; s=arc-20160816; b=uBtWgcaQtC7wMP2x2XakJJb5z1/wuM305CdvL08lwGPWg5hJuMsqn4oB/EW0bdaSXU XnpmYh7r5v2ysJrTer/EZhCw5HJbGWne6JZ69d5897NvLD9HSsypvVO2VtnLYpTy3Dio B48xD44pMKvZFVkwmZFtWYaAtlpGWxKzztD3OXEmaGO7kS9/KL+1JgKxBM1255r9BYRc lIWe8F2SC7t+N5ITxhN/byMzvvGFrXRpbaFOzjG8Fd3P+wQs/q9HvDYXC26G0zWZGpun UMEewzQR3onzuFisbD+0jiTo3qjeaQagcuvmsP8pDymuqdu7fE6kf0R7jSyQLvypUY0J u+Gg== 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=oLKpvX91YG+jy/JoBXU81k3iJpiW5DBSQzEq361ASJE=; b=PnVzEreGBgFGBZcXDmJeE24Q/2s0HN8frrtnXoYfl/wQ/1LWIpC0IzmatWrkv/Z+/5 0RtlM6inc8v8BbkTnGudI3C9J5/VDbWKsaUcwTz4dv01wYfPm7JzLRBX0vQE9jD3Mp4n vcRKpjH94zNxzCk8or8mPEkJz1Pv0Bt5Psy9Q7jz+P5PaiAod94Sufdh/dooXZvDgFg7 uPr7bCOmM7fH5CyUG0gnO4mjzR4H0QQLFYfXfxdo9EFIFh6NTRBUYR3+ukogelXjG5IJ KaqADf74B+j5rMQxKLvdmDctQVc0YFEBs8lLk3/eNGjaMBajmepoGK7dzGN4bgaFD7YL kVxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=MEvLIcJf; 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 my22-20020a1709065a5600b0077c5ec87ec2si4159022ejc.297.2022.10.28.10.11.26; Fri, 28 Oct 2022 10:11:50 -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=MEvLIcJf; 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 S231386AbiJ1RKu (ORCPT + 99 others); Fri, 28 Oct 2022 13:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbiJ1RKC (ORCPT ); Fri, 28 Oct 2022 13:10:02 -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 280496314; Fri, 28 Oct 2022 10:07:49 -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 95935218D; Fri, 28 Oct 2022 17:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976708; bh=oLKpvX91YG+jy/JoBXU81k3iJpiW5DBSQzEq361ASJE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=MEvLIcJf4AQfUWH6jf+sxNEzkH4yi9p5kEuz5PMu5Ji3q5MBr29NIGaz4+2orzMyF W4MHeS7QMuTQ0tQRRWeBLC/HoBIUn/hry5fz22c9CCJca5mtNOcBhV6c7FS/R/bbwF kq3W0wsE5QIJK2IxchV2P/Vog3yfIHZMuCvDoi9I= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:07:47 +0300 Message-ID: <009f0b29-cc50-f162-9e23-27517c76cae6@paragon-software.com> Date: Fri, 28 Oct 2022 20:07:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 13/14] fs/ntfs3: Improve checking of bad clusters Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952191179437691?= X-GMAIL-MSGID: =?utf-8?q?1747952191179437691?= Added new function wnd_set_used_safe. Load $BadClus before $AttrDef instead of before $Bitmap. Signed-off-by: Konstantin Komarov --- fs/ntfs3/bitmap.c | 38 +++++++++++++++++++++++++++ fs/ntfs3/ntfs_fs.h | 2 ++ fs/ntfs3/run.c | 21 ++------------- fs/ntfs3/super.c | 64 ++++++++++++++++++++++++++++------------------ 4 files changed, 81 insertions(+), 44 deletions(-) diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 6e68887597ac..c86a76dd44b9 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -800,6 +800,44 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits) return err; } +/* + * wnd_set_used_safe - Mark the bits range from bit to bit + bits as used. + * + * Unlikely wnd_set_used/wnd_set_free this function is not full trusted. + * It scans every bit in bitmap and marks free bit as used. + * @done - how many bits were marked as used. + * + * NOTE: normally *done should be 0. + */ +int wnd_set_used_safe(struct wnd_bitmap *wnd, size_t bit, size_t bits, + size_t *done) +{ + size_t i, from = 0, len = 0; + int err = 0; + + *done = 0; + for (i = 0; i < bits; i++) { + if (wnd_is_free(wnd, bit + i, 1)) { + if (!len) + from = bit + i; + len += 1; + } else if (len) { + err = wnd_set_used(wnd, from, len); + *done += len; + len = 0; + if (err) + break; + } + } + + if (len) { + /* last fragment. */ + err = wnd_set_used(wnd, from, len); + *done += len; + } + return err; +} + /* * wnd_is_free_hlp * diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index bc02cfb344f9..2f55993a716c 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -826,6 +826,8 @@ static inline size_t wnd_zeroes(const struct wnd_bitmap *wnd) int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits); int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits); int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits); +int wnd_set_used_safe(struct wnd_bitmap *wnd, size_t bit, size_t bits, + size_t *done); bool wnd_is_free(struct wnd_bitmap *wnd, size_t bit, size_t bits); bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits); diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c index 12d8682f33b5..a5af71cd8d14 100644 --- a/fs/ntfs3/run.c +++ b/fs/ntfs3/run.c @@ -1096,25 +1096,8 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino, if (down_write_trylock(&wnd->rw_lock)) { /* Mark all zero bits as used in range [lcn, lcn+len). */ - CLST i, lcn_f = 0, len_f = 0; - - err = 0; - for (i = 0; i < len; i++) { - if (wnd_is_free(wnd, lcn + i, 1)) { - if (!len_f) - lcn_f = lcn + i; - len_f += 1; - } else if (len_f) { - err = wnd_set_used(wnd, lcn_f, len_f); - len_f = 0; - if (err) - break; - } - } - - if (len_f) - err = wnd_set_used(wnd, lcn_f, len_f); - + size_t done; + err = wnd_set_used_safe(wnd, lcn, len, &done); up_write(&wnd->rw_lock); if (err) return err; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 1e2c04e48f98..d8ba6724adf1 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -921,7 +921,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) struct block_device *bdev = sb->s_bdev; struct inode *inode; struct ntfs_inode *ni; - size_t i, tt; + size_t i, tt, bad_len, bad_frags; CLST vcn, lcn, len; struct ATTRIB *attr; const struct VOLUME_INFO *info; @@ -1091,30 +1091,6 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) sbi->mft.ni = ni; - /* Load $BadClus. */ - ref.low = cpu_to_le32(MFT_REC_BADCLUST); - ref.seq = cpu_to_le16(MFT_REC_BADCLUST); - inode = ntfs_iget5(sb, &ref, &NAME_BADCLUS); - if (IS_ERR(inode)) { - ntfs_err(sb, "Failed to load $BadClus."); - err = PTR_ERR(inode); - goto out; - } - - ni = ntfs_i(inode); - - for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) { - if (lcn == SPARSE_LCN) - continue; - - if (!sbi->bad_clusters) - ntfs_notice(sb, "Volume contains bad blocks"); - - sbi->bad_clusters += len; - } - - iput(inode); - /* Load $Bitmap. */ ref.low = cpu_to_le32(MFT_REC_BITMAP); ref.seq = cpu_to_le16(MFT_REC_BITMAP); @@ -1152,6 +1128,44 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) if (err) goto out; + /* Load $BadClus. */ + ref.low = cpu_to_le32(MFT_REC_BADCLUST); + ref.seq = cpu_to_le16(MFT_REC_BADCLUST); + inode = ntfs_iget5(sb, &ref, &NAME_BADCLUS); + if (IS_ERR(inode)) { + err = PTR_ERR(inode); + ntfs_err(sb, "Failed to load $BadClus (%d).", err); + goto out; + } + + ni = ntfs_i(inode); + bad_len = bad_frags = 0; + for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) { + if (lcn == SPARSE_LCN) + continue; + + bad_len += len; + bad_frags += 1; + if (sb_rdonly(sb)) + continue; + + if (wnd_set_used_safe(&sbi->used.bitmap, lcn, len, &tt) || tt) { + /* Bad blocks marked as free in bitmap. */ + ntfs_set_state(sbi, NTFS_DIRTY_ERROR); + } + } + if (bad_len) { + /* + * Notice about bad blocks. + * In normal cases these blocks are marked as used in bitmap. + * And we never allocate space in it. + */ + ntfs_notice(sb, + "Volume contains %zu bad blocks in %zu fragments.", + bad_len, bad_frags); + } + iput(inode); + /* Load $AttrDef. */ ref.low = cpu_to_le32(MFT_REC_ATTR); ref.seq = cpu_to_le16(MFT_REC_ATTR); From patchwork Fri Oct 28 17:08:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 12497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp945741wru; Fri, 28 Oct 2022 10:12:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4AHhCtfa8LIdk9sybVDNDxucB7g0SAjd+7zl3fg3QtwbiqRynjABIhEjTBkKssued/WNnG X-Received: by 2002:a17:902:dac4:b0:186:c372:732a with SMTP id q4-20020a170902dac400b00186c372732amr346356plx.174.1666977134046; Fri, 28 Oct 2022 10:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977134; cv=none; d=google.com; s=arc-20160816; b=xN87vFG2JF1Xr/dV2/+oZudxxsVvW1NuQIe9DWDvbENghYFIx+LijsNPikxZZDSkwP 0jN2SLIxDtcxTxgOsrled4T6MaeH2GUoL3gHFvyYkeCBDSIcyajwBN4f+vghJNTja1Ia VLGc11G7Gsk4nVKfK/Trs32IVAdIf78m8o7OTUmSacYqO0zDupyVzcLQa5IzskHs9Ami LDz/l7iAJ0qaBihSCN/tsCpOXMWzJHty9qMmUPtTmm3Sec14c+7PBdrAsiuynKeTVqp2 DFjorCt2dkQKZlhLTf0s9xRSxCHwUJvCTXwctpFdoHUR0wuj1jEgaHvDp09jXagr43Gg GLRg== 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=TVrq+vQGb+av6ii3jqQDdjetxf7DCNwUg01zC3qewKs=; b=P2D201BIkadqJEP/fvPWZQmj00FWmmw856b+yKW9WuhkvS3zsrR2dfYrcwQTedE7nA uVyXCWV325IrRf8hxsQHuR71ouagOCiJL9W6pdPgHQbqOVlfpcuF7nFDycGcsnCgWyHb lbDfmbh2T1nwXC0zQ7EDVnbiShAkwBR+aVMKHfmCXC+/Qgcy4tkpzbV7oLebDc8TBfVp 3JTMLjZFD+4MOEE2EEY0+OrFih3ZaPzcGoMnb2k2Un8FxwRnJi1DhA35VhAG03lDtlTn YJw2eIHeJH+hgMtYcYkSDTGlChH6UilvhzyYUmZfx08KiY03I9HCuyirB/w620vwN/xB LdsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=gAXYhGKx; dkim=pass header.i=@paragon-software.com header.s=mail header.b=SP66XS7J; 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 g1-20020a636b01000000b0046f729604f6si2034852pgc.174.2022.10.28.10.11.59; Fri, 28 Oct 2022 10:12: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=gAXYhGKx; dkim=pass header.i=@paragon-software.com header.s=mail header.b=SP66XS7J; 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 S230437AbiJ1RLB (ORCPT + 99 others); Fri, 28 Oct 2022 13:11:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbiJ1RKV (ORCPT ); Fri, 28 Oct 2022 13:10:21 -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 C55BF77547; Fri, 28 Oct 2022 10:08:12 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id D9FE9218D; Fri, 28 Oct 2022 17:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976731; bh=TVrq+vQGb+av6ii3jqQDdjetxf7DCNwUg01zC3qewKs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=gAXYhGKxNxS9jnSw23PcRE5QSOyUUHsJS9hpwu6oX845dwVSgtxDTaYmuMZIQo+V9 6GcmRS4YmY7zplFzNuA4W1Vv6sY0QpIHvQvJNpuO91Or4DaZUNcpoAkRiW6iGxiPDW 4YOLMtZiCt+7tdxeyPSwh0Zp4SDG3KDHz2FDJmic= 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 D903FDD; Fri, 28 Oct 2022 17:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976890; bh=TVrq+vQGb+av6ii3jqQDdjetxf7DCNwUg01zC3qewKs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=SP66XS7JeULWj/kAbmS0oBErTfmLbpWHzNenHpvvq2OrXoCm3M8C9xMZEWMk6qhZc JBR1wBN9NqKS5jjlM0i0P5j/gKDLH4fqIkoa37jFcIioV6374q76PrLPFu3uV5N5ao XEkH+gxx84TbiHvTDubs+tUbLMtrwJ0Qes6WjEvo= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 28 Oct 2022 20:08:10 +0300 Message-ID: <2f497702-ace1-9b3e-65d1-a7dc57623372@paragon-software.com> Date: Fri, 28 Oct 2022 20:08:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 14/14] fs/ntfs3: Make if more readable Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-Originating-IP: [172.30.8.65] 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 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?1747952215026379509?= X-GMAIL-MSGID: =?utf-8?q?1747952215026379509?= This way it looks better. Signed-off-by: Konstantin Komarov --- fs/ntfs3/record.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index a952cd7aa7a4..defce6a5c8e1 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -265,10 +265,9 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) if (t16 + t32 > asize) return NULL; - if (attr->name_len && - le16_to_cpu(attr->name_off) + sizeof(short) * attr->name_len > t16) { + t32 = sizeof(short) * attr->name_len; + if (t32 && le16_to_cpu(attr->name_off) + t32 > t16) return NULL; - } return attr; }