From patchwork Thu Dec 22 10:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079560 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96ED8C4167B for ; Thu, 22 Dec 2022 10:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235273AbiLVKQS (ORCPT ); Thu, 22 Dec 2022 05:16:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235149AbiLVKQR (ORCPT ); Thu, 22 Dec 2022 05:16:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D0C6462 for ; Thu, 22 Dec 2022 02:16:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 956648D589; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r5N0xOwUSqyGUKgtFC52PIjPv/er7HVrcdK2etrPkTE=; b=Iym4y0NjtBYPwM1mc4WvFn3C7BPr/uTPMAffvuiJrWX8Ys/bytn+1R/b74b3BkKLD2orEY YbBB44gKEXD4E6i93Bf/wGOGFPiujzVf8oYDKVRVvD16eH5t70UWSaHhqB+WM4U6DIP+4l 5UP6aCFkXBedd2at8Qngm8dsoLJfPZY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r5N0xOwUSqyGUKgtFC52PIjPv/er7HVrcdK2etrPkTE=; b=0QzNDiYw6KUtqFKbbBsL2cUmq2n4h7MIIu636+jwmXlhCcapwe9Tz3/ZzteKREIoogL5Nk Bhg9jVclFB+DRiCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6E8C91391C; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QUP5Gm4upGMxWwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0AF24A071C; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 1/7] udf: Handle error when expanding directory Date: Thu, 22 Dec 2022 11:15:58 +0100 Message-Id: <20221222101612.18814-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1006; i=jack@suse.cz; h=from:subject; bh=nj1dyUcvok/3ME6MbG+EF2pgGQY+QqHMVUhP5hAJirI=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5eON9WLES5geU3IrZaitEZo9i+FRuTSB4yA9B/ zz7m/LaJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuXgAKCRCcnaoHP2RA2a9MB/ 0RNNhEb9iMGTWmz1X+lNWYn4jWl4c8jlfWM7xNJbXX3DXAJuJl4Fbl7Id5fLvmJXfiU2+JIo8he041 fhYBuA9n1k8KJVQTUgAOOFQMb/roSHbNgoWRNb/BejHWo/dBhh35m76Kq5MjUvIC8nSpSfUpSGko/o FIY7+DHycSS0oQWidXI7ZYK6e/02MexZxboLSgtBBknz+JOBCM/jA3kD0lHyDKYUVtAYQZ74tnCnz6 Eb4bNjlsqZ2E9IEAjnupVsFt14pRqLKGljv/zpKHtcsOOqbrEv+cxS+X2QUkb3yPZV+8G4C6Qqn0wf RJWfirIvS7X/P3CEX6bgzwM/+Mtzsl X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When there is an error when adding extent to the directory to expand it, make sure to propagate the error up properly. This is not expected to happen currently but let's make the code more futureproof. Signed-off-by: Jan Kara --- fs/udf/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 800271b00f84..de169feacce9 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -192,8 +192,13 @@ static struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, epos.bh = NULL; epos.block = iinfo->i_location; epos.offset = udf_file_entry_alloc_offset(inode); - udf_add_aext(inode, &epos, &eloc, inode->i_size, 0); + ret = udf_add_aext(inode, &epos, &eloc, inode->i_size, 0); brelse(epos.bh); + if (ret < 0) { + *err = ret; + udf_free_blocks(inode->i_sb, inode, &eloc, 0, 1); + return NULL; + } mark_inode_dirty(inode); /* Now fixup tags in moved directory entries */ From patchwork Thu Dec 22 10:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49AF2C4167B for ; Thu, 22 Dec 2022 10:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235305AbiLVKQ1 (ORCPT ); Thu, 22 Dec 2022 05:16:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235265AbiLVKQS (ORCPT ); Thu, 22 Dec 2022 05:16:18 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 422F664E4 for ; Thu, 22 Dec 2022 02:16:17 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7EC9A44F2; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0q3+yIxhP6B4IWiv038KzQr+jMC/MRZWST7+qxNvchY=; b=rPM8MgcMgiXONHkC7/8NuSncLADsmiU6BffDfXrOMyGGwQoob3zKd6zj0sfb65qm8Xl89c qalN1KkYJb367rJQdo6zTDEwCECOMYQ+5rTlZiD/hAKf0lgp5dLElY0ahk3hjeURFBhDQD crMfilmTTDtq2z5bo2HViEjeH8hmH+c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0q3+yIxhP6B4IWiv038KzQr+jMC/MRZWST7+qxNvchY=; b=tLWEvWJ5uft0GBvcrLsv6NfzUacq+eJWHTtE1pQ4yrS2OFkwgHiwqRNdZngTqa/fveK9mZ YrLYTzKqjNUiqyCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5BA5913919; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WHCRFW4upGMrWwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 10A06A0735; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 2/7] udf: Handle error when adding extent to symlink Date: Thu, 22 Dec 2022 11:15:59 +0100 Message-Id: <20221222101612.18814-2-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1222; i=jack@suse.cz; h=from:subject; bh=qSBuG4kED5vLXelZ+uZNkeJm+Ss6athpPpTDDWNhsX4=; b=owGbwMvMwME4Z+4qdvsUh5uMp9WSGJKX6MWzcpmUhcv9+FEjHTenvz/rgdFNLcf45lcx38Ommopr s/Z1MhqzMDByMMiKKbKsjryofW2eUdfWUA0ZmEGsTCBTGLg4BWAiu+rZ/7ut46t5Jjp7bnLq4xNyt1 7UxHRkSZoZbTI/PV/2n5herMvdvymzz/n+YSzLXejbuF9YY8lHi8ZPzd+Y/NUsztY86/svOunv7qlc 8wWPiNtqMF6eemLvB+6rO3qY7+6Mawo7q6vp81ZE7mQTQ5DBualsC7JvP/s6c2Hwiu+Xpc/ICbCy1E 3jutft12A7NzpIYPmbbzZMBq4LDaNdpWQWFFjlpy7Zssz/mXCT2x2baiUJs99fbyumn+Xlr1K8s/i7 mmiJn8f5CcaK8pc8Hqmpc3+KKci8Wcsl1B9gvqRu3eu0lFIB7WWJhU8qWSduWF0gNE3wyYcl0ow8qh 8YexbNTVoUaSZjyfh2j1vxrqclAA== X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When adding extent describing symlink data fails, make sure to handle the error properly, propagate it up and free the already allocated block. Signed-off-by: Jan Kara --- fs/udf/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index de169feacce9..2ade040483a1 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -609,8 +609,12 @@ static int udf_symlink(struct user_namespace *mnt_userns, struct inode *dir, iinfo->i_location.partitionReferenceNum; bsize = sb->s_blocksize; iinfo->i_lenExtents = bsize; - udf_add_aext(inode, &epos, &eloc, bsize, 0); + err = udf_add_aext(inode, &epos, &eloc, bsize, 0); brelse(epos.bh); + if (err < 0) { + udf_free_blocks(sb, inode, &eloc, 0, 1); + goto out_no_entry; + } block = udf_get_pblock(sb, block, iinfo->i_location.partitionReferenceNum, @@ -618,6 +622,7 @@ static int udf_symlink(struct user_namespace *mnt_userns, struct inode *dir, epos.bh = udf_tgetblk(sb, block); if (unlikely(!epos.bh)) { err = -ENOMEM; + udf_free_blocks(sb, inode, &eloc, 0, 1); goto out_no_entry; } lock_buffer(epos.bh); From patchwork Thu Dec 22 10:16:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A99C4332F for ; Thu, 22 Dec 2022 10:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235281AbiLVKQV (ORCPT ); Thu, 22 Dec 2022 05:16:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235193AbiLVKQR (ORCPT ); Thu, 22 Dec 2022 05:16:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D13E6479 for ; Thu, 22 Dec 2022 02:16:16 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8641E4504; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0nGbOvNXrbr0L7puljLzPnbZHHS9uUvQyAtSaFZMTo=; b=tZwP9xGZPzFld8XmWiWG/ebD8a2YJE1XBrevRdfPyL4PG4YB5aYUaozSK1aj7j3nbg4fDF XyoAJmh8AQAnYGXoCepC+2A5X6hC1QiSh1xGHCZlPYDC5rmU5zHdnhQ/ibpnDWTTi8fDnU g3jgCvWILnTOho/AF9sqw1JLIPH0Y10= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0nGbOvNXrbr0L7puljLzPnbZHHS9uUvQyAtSaFZMTo=; b=r9YZyYv9C4LBlmkOmmecDuU8csxUNtf4B7EKvtLgtE8MOkXmrnR5TjS4o6qLQLUAcO8Msz 0/+JC6WWViUvmVAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5F3131391A; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EG+/Fm4upGMsWwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 16DD0A0736; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 3/7] udf: Handle error when adding extent to a file Date: Thu, 22 Dec 2022 11:16:00 +0100 Message-Id: <20221222101612.18814-3-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4633; i=jack@suse.cz; h=from:subject; bh=9MgG21OefY4ia2mEWbI6seab3vZrzr+uMEedOhqns9Q=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5g6V3PRRheOzBRgHhuU2L3Ai7CfHsbjDmigRzA 4k4sE32JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuYAAKCRCcnaoHP2RA2cKDCA DgkHdnSNSROfHMWJfMcrYKAyad7E9Y2Xb6/5it1bYKdBMr+6NNk2Y1iyfaHvcQUX7qLl9oGxfEnEIb DDtQ5QhqXaGbS3e2Hp5UowrpdFq3O+WtwLbVTC3UvlWMR9Ough158Ez77DXps70BKnBl5YDFn76Kqy Al5BLDpAilaimh4KbUrhjY7MXMuSmO1B2b5utOkT0k0Z9sKAYxYPRM7/KXu9/T8kV2HSW1lYXUgGo4 uIx1P2bOiWkK86T2KtFBrqGqKZ+Fbhrxwhtqz8iVw/mKXVkVG80USoo4P0pFmxFqWO6xSWng+wzH5p TmqqUWKYxGAhD+LBvByTPNbrY/J1VQ X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When adding extent to a file fails, so far we've silently squelshed the error. Make sure to propagate it up properly. Signed-off-by: Jan Kara --- fs/udf/inode.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 09417342d8b6..15b3e529854b 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -57,15 +57,15 @@ static int udf_update_inode(struct inode *, int); static int udf_sync_inode(struct inode *inode); static int udf_alloc_i_data(struct inode *inode, size_t size); static sector_t inode_getblk(struct inode *, sector_t, int *, int *); -static int8_t udf_insert_aext(struct inode *, struct extent_position, - struct kernel_lb_addr, uint32_t); +static int udf_insert_aext(struct inode *, struct extent_position, + struct kernel_lb_addr, uint32_t); static void udf_split_extents(struct inode *, int *, int, udf_pblk_t, struct kernel_long_ad *, int *); static void udf_prealloc_extents(struct inode *, int, int, struct kernel_long_ad *, int *); static void udf_merge_extents(struct inode *, struct kernel_long_ad *, int *); -static void udf_update_extents(struct inode *, struct kernel_long_ad *, int, - int, struct extent_position *); +static int udf_update_extents(struct inode *, struct kernel_long_ad *, int, + int, struct extent_position *); static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); static void __udf_clear_extent_cache(struct inode *inode) @@ -795,7 +795,9 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, /* write back the new extents, inserting new extents if the new number * of extents is greater than the old number, and deleting extents if * the new number of extents is less than the old number */ - udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); + *err = udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); + if (*err < 0) + goto out_free; newblock = udf_get_pblock(inode->i_sb, newblocknum, iinfo->i_location.partitionReferenceNum, 0); @@ -1063,21 +1065,30 @@ static void udf_merge_extents(struct inode *inode, struct kernel_long_ad *laarr, } } -static void udf_update_extents(struct inode *inode, struct kernel_long_ad *laarr, - int startnum, int endnum, - struct extent_position *epos) +static int udf_update_extents(struct inode *inode, struct kernel_long_ad *laarr, + int startnum, int endnum, + struct extent_position *epos) { int start = 0, i; struct kernel_lb_addr tmploc; uint32_t tmplen; + int err; if (startnum > endnum) { for (i = 0; i < (startnum - endnum); i++) udf_delete_aext(inode, *epos); } else if (startnum < endnum) { for (i = 0; i < (endnum - startnum); i++) { - udf_insert_aext(inode, *epos, laarr[i].extLocation, - laarr[i].extLength); + err = udf_insert_aext(inode, *epos, + laarr[i].extLocation, + laarr[i].extLength); + /* + * If we fail here, we are likely corrupting the extent + * list and leaking blocks. At least stop early to + * limit the damage. + */ + if (err < 0) + return err; udf_next_aext(inode, epos, &laarr[i].extLocation, &laarr[i].extLength, 1); start++; @@ -1089,6 +1100,7 @@ static void udf_update_extents(struct inode *inode, struct kernel_long_ad *laarr udf_write_aext(inode, epos, &laarr[i].extLocation, laarr[i].extLength, 1); } + return 0; } struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block, @@ -2107,12 +2119,13 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, return etype; } -static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos, - struct kernel_lb_addr neloc, uint32_t nelen) +static int udf_insert_aext(struct inode *inode, struct extent_position epos, + struct kernel_lb_addr neloc, uint32_t nelen) { struct kernel_lb_addr oeloc; uint32_t oelen; int8_t etype; + int err; if (epos.bh) get_bh(epos.bh); @@ -2122,10 +2135,10 @@ static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos, neloc = oeloc; nelen = (etype << 30) | oelen; } - udf_add_aext(inode, &epos, &neloc, nelen, 1); + err = udf_add_aext(inode, &epos, &neloc, nelen, 1); brelse(epos.bh); - return (nelen >> 30); + return err; } int8_t udf_delete_aext(struct inode *inode, struct extent_position epos) From patchwork Thu Dec 22 10:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CA8BC4332F for ; Thu, 22 Dec 2022 10:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235211AbiLVKQT (ORCPT ); Thu, 22 Dec 2022 05:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235142AbiLVKQR (ORCPT ); Thu, 22 Dec 2022 05:16:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1273A55BC for ; Thu, 22 Dec 2022 02:16:15 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 72B368D583; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ob8c9Xl5jq53VeacCXuNWmFpNKrFVafBptA4tCW+0gQ=; b=n8LGLNZRFUJYfKpzkh9iLrzmhpk8HF8YF+pLUdxPpM4GFb0DdibS72LzsxCXH2Q8maFrMZ kN2jTLeXmtIVS3qNktzDg7IUGUAXVLGLBYFbUAGZBSsZuAvdR8bGyPmoTmH6VjhgsuCARq G9hueAVg3b00t5WQwhQ3H/lwB5CVtws= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ob8c9Xl5jq53VeacCXuNWmFpNKrFVafBptA4tCW+0gQ=; b=4y5RYAU1EJWVO8SeSeYMAwkzsTWdjY1Lu6F8aMNArPjTVKws6eMRFrou0Inzc8i1bBrK2j p4uv+lqnp1gA3ZDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4A67913918; Thu, 22 Dec 2022 10:16:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +1AbEm4upGMnWwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:14 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1C82BA073E; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara , kernel test robot Subject: [PATCH 4/7] udf: Allocate name buffer in directory iterator on heap Date: Thu, 22 Dec 2022 11:16:01 +0100 Message-Id: <20221222101612.18814-4-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2866; i=jack@suse.cz; h=from:subject; bh=3QHtjGUzPT3PbkmFlUzWkLznjZG7or7IG3j6sXc24Wo=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5hdDPzIdjlQHgWSTzbV4gztChf5drH/YJtnOUa v7LZqpOJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuYQAKCRCcnaoHP2RA2SidCA Dk3+AIucI/oy0C7WzxABHabH02C7E0Jgk5oIvFzL1LL8Ilpq6Vliu78IY0hYTL8SXWczg0zJzmftwC YXykJSPc3yKOZ3YokNBdKmtj3/UXlv4PbQFaMQwAV99sk8y5HHNmZ8Jfsxwehh03kEB3M6nFW+jYJD m0kOWtXt09GyLVQ021vGCCQz7n1Qs4YH9AVjkzYFzVsn5xjsMdjE2wz9uFZGWiRYZlTpgxhnLdOHr/ eswnhrPmnX5nchBQzpl7PfwVfgcF5yGQP8dv/1Me2+7rcCqqEwv2gRKL/OIvc0MvGRRIc8JkAYOxNc cOnEvKS6M2UZYQRu75agxOpv2PXkja X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently we allocate name buffer in directory iterators (struct udf_fileident_iter) on stack. These structures are relatively large (some 360 bytes on 64-bit architectures). For udf_rename() which needs to keep three of these structures in parallel the stack usage becomes rather heavy - 1536 bytes in total. Allocate the name buffer in the iterator from heap to avoid excessive stack usage. Link: https://lore.kernel.org/all/202212200558.lK9x1KW0-lkp@intel.com Reported-by: kernel test robot Signed-off-by: Jan Kara --- fs/udf/directory.c | 23 +++++++++++++++-------- fs/udf/udfdecl.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/udf/directory.c b/fs/udf/directory.c index 9e6a54445f90..0f3cc095b2a3 100644 --- a/fs/udf/directory.c +++ b/fs/udf/directory.c @@ -248,9 +248,14 @@ int udf_fiiter_init(struct udf_fileident_iter *iter, struct inode *dir, iter->elen = 0; iter->epos.bh = NULL; iter->name = NULL; + iter->namebuf = kmalloc(UDF_NAME_LEN_CS0, GFP_KERNEL); + if (!iter->namebuf) + return -ENOMEM; - if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) - return udf_copy_fi(iter); + if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { + err = udf_copy_fi(iter); + goto out; + } if (inode_bmap(dir, iter->pos >> dir->i_blkbits, &iter->epos, &iter->eloc, &iter->elen, &iter->loffset) != @@ -260,17 +265,17 @@ int udf_fiiter_init(struct udf_fileident_iter *iter, struct inode *dir, udf_err(dir->i_sb, "position %llu not allocated in directory (ino %lu)\n", (unsigned long long)pos, dir->i_ino); - return -EFSCORRUPTED; + err = -EFSCORRUPTED; + goto out; } err = udf_fiiter_load_bhs(iter); if (err < 0) - return err; + goto out; err = udf_copy_fi(iter); - if (err < 0) { +out: + if (err < 0) udf_fiiter_release(iter); - return err; - } - return 0; + return err; } int udf_fiiter_advance(struct udf_fileident_iter *iter) @@ -307,6 +312,8 @@ void udf_fiiter_release(struct udf_fileident_iter *iter) brelse(iter->bh[0]); brelse(iter->bh[1]); iter->bh[0] = iter->bh[1] = NULL; + kfree(iter->namebuf); + iter->namebuf = NULL; } static void udf_copy_to_bufs(void *buf1, int len1, void *buf2, int len2, diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index f764b4d15094..d35aa42bb577 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -99,7 +99,7 @@ struct udf_fileident_iter { struct extent_position epos; /* Position after the above extent */ struct fileIdentDesc fi; /* Copied directory entry */ uint8_t *name; /* Pointer to entry name */ - uint8_t namebuf[UDF_NAME_LEN_CS0]; /* Storage for entry name in case + uint8_t *namebuf; /* Storage for entry name in case * the name is split between two blocks */ }; From patchwork Thu Dec 22 10:16:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C663AC4332F for ; Thu, 22 Dec 2022 10:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235310AbiLVKQ3 (ORCPT ); Thu, 22 Dec 2022 05:16:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235271AbiLVKQS (ORCPT ); Thu, 22 Dec 2022 05:16:18 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A01D656A for ; Thu, 22 Dec 2022 02:16:17 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4A31E450A; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wsty5jhjCjY1hQnFIQVKu4GMgQFq8mfuqTz0AWhEuhM=; b=AKo2kdSwAnoBI/ycyXlRfXWxELXW7tWQnDDElnHEJnpa2fRoHKnc0G7ylnHcW+8PgEnh27 lqOV0BT7FYCaRBLpNML4PjEgRAuHmsHLH3F8FPHmM9uPJ4NPejB2ii8Oh5bSt9NsAfcoPA +esK6wuf8PHjUS608xeC4o/qBWK/qvc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wsty5jhjCjY1hQnFIQVKu4GMgQFq8mfuqTz0AWhEuhM=; b=dTJ/O6peN5oeuVgdI4CqIcZjjB9PEZqqu5BqOdkIuHoVS/HW7WjyfBU9hvGeDE/nPcw3TR 2O0RJ2qnSYf7sYBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 19DB913919; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kYBJBnAupGM7WwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:16 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 22B27A0742; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 5/7] udf: Move setting of i_lenExtents into udf_do_extend_file() Date: Thu, 22 Dec 2022 11:16:02 +0100 Message-Id: <20221222101612.18814-5-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1817; i=jack@suse.cz; h=from:subject; bh=xyoN7AngrBdg2o4OYF4YB/kbkvIdNNJU9naNQV32cso=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5iaFxznBF1Fhc7j198rjTuKbouaYKaMpbXBeTt l/+/gbSJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuYgAKCRCcnaoHP2RA2abJCA CmikLnKio4gB196NJ2DfY3XaaNFhczNtiFQOcpLLTae+jF84S92mD/YnDPj/H3V3GKrZq21AHo/bz2 48Rb43BfkAxpA/9WXirwpZ0gswM8zdzm3Tu6wV0WUrWFQ/WensGSmSqg26lpKIkPf6Ed+c8Qn69i+4 M2RX17WBx+DYctyKPRhWAPPxh8+fsXBpix6/3c+YrkfrVZIvEhqEEZt1F4er0dhiKEqJdt3AszeeQW tECQMu+A+HnS1GLb/T5nmohIEji1uDPjkH+mQsTV16b5bAd9k3rTvTYPk+KFQi5YVx0ub3i/RTZP4L 3bkRZGPTNqvE4pNFXTCy7oGG3d9+wE X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When expanding file for a write into a hole, we were not updating total length of inode's extents properly. Move the update of i_lenExtents into udf_do_extend_file() so that both expanding of file by truncate and expanding of file by writing beyond EOF properly update the length of extents. As a bonus, we also correctly update the length of extents when only part of extents can be written. Signed-off-by: Jan Kara --- fs/udf/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 15b3e529854b..fe5b0ba600fa 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -419,6 +419,7 @@ static int udf_do_extend_file(struct inode *inode, ~(sb->s_blocksize - 1); } + add = 0; /* Can we merge with the previous extent? */ if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { @@ -451,6 +452,7 @@ static int udf_do_extend_file(struct inode *inode, if (new_block_bytes) udf_next_aext(inode, last_pos, &tmploc, &tmplen, 0); } + iinfo->i_lenExtents += add; /* Managed to do everything necessary? */ if (!new_block_bytes) @@ -469,6 +471,7 @@ static int udf_do_extend_file(struct inode *inode, last_ext->extLength, 1); if (err) goto out_err; + iinfo->i_lenExtents += add; count++; } if (new_block_bytes) { @@ -478,6 +481,7 @@ static int udf_do_extend_file(struct inode *inode, last_ext->extLength, 1); if (err) goto out_err; + iinfo->i_lenExtents += new_block_bytes; count++; } @@ -585,7 +589,6 @@ static int udf_extend_file(struct inode *inode, loff_t newsize) if (err < 0) goto out; err = 0; - iinfo->i_lenExtents = newsize; out: brelse(epos.bh); return err; From patchwork Thu Dec 22 10:16:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90797C4167B for ; Thu, 22 Dec 2022 10:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235248AbiLVKQa (ORCPT ); Thu, 22 Dec 2022 05:16:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235033AbiLVKQT (ORCPT ); Thu, 22 Dec 2022 05:16:19 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC00F8FF0 for ; Thu, 22 Dec 2022 02:16:17 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 525DC8D58C; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mMcltPErAnUaZ2E8MZ1BVqgqjs7++N3jLvuu2D02bdA=; b=GjD1/ZyPCwZp1afDCrVUXi/sHHH2fb+zONb6hbFWNenuQysNGJX61zjKeT3CRYbDDDUkBA ACGUqAlYCuXPVTiS+ThjrA+ef5lRcWTNbzXf3kaZ5ueb9hJkTI7O7WG+xFpUHRSdDpv5BO 8iNOD+3s/4h9biBfrBGDxF4Jo5Fzwss= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mMcltPErAnUaZ2E8MZ1BVqgqjs7++N3jLvuu2D02bdA=; b=aXTjB5FzRsGpQRVfH4gj4xVCHjrpzmkXS5427f+lkQI/6QXA8XFz9Opd4g8d5gAHTn23G0 8bG3TOx52VVYe6Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1E3DE1391A; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EpFgB3AupGM9WwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:16 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 28BB0A0744; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 6/7] udf: Fix extension of the last extent in the file Date: Thu, 22 Dec 2022 11:16:03 +0100 Message-Id: <20221222101612.18814-6-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1005; i=jack@suse.cz; h=from:subject; bh=Gcl4YFJQZhSE3h/xrjpJZCPX9KgF4bSBNznIlnESTJk=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5jkulY2Mkvbs8L3Gkl+AQm8ZZweMRXSQKWDIR0 21bd1xWJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuYwAKCRCcnaoHP2RA2bTzB/ wPMa0bbWfkqdbhGQr0wKo/UKXsZHBwX2pAskSH2znfzgnkRDSh4Sn22H5GVm91kz7QtHMqm1htLGRW SutQlDYYXgY3Cc7RGits9ToA1qHM8fFM+62ynHWwD+3CmOe9lYYYuGcdUzDeQASpi7CCrBp3pKXZqE thRW/2KoS4mRjK6KAS00mpYnDB0vN771J70K3DXHY3sVCta9RebaUYah119r6GYKtqSayvx+7OmMlG D889fhcwecEIM6GlUNgdLZj1egu1jGMXy8BPfiqD+aarDiAyTBi9zApl6CSiNkDmlWROQkehfWBjc7 hfZuHIviM3SHZZvc7HPfFWmia3MYbV X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When extending the last extent in the file within the last block, we wrongly computed the length of the last extent. This is mostly a cosmetical problem since the extent does not contain any data and the length will be fixed up by following operations but still. Fixes: 1f3868f06855 ("udf: Fix extending file within last block") Signed-off-by: Jan Kara --- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index fe5b0ba600fa..075e0a9d766c 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -516,7 +516,7 @@ static void udf_do_extend_final_block(struct inode *inode, */ if (new_elen <= (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) return; - added_bytes = (last_ext->extLength & UDF_EXTENT_LENGTH_MASK) - new_elen; + added_bytes = new_elen - (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); last_ext->extLength += added_bytes; UDF_I(inode)->i_lenExtents += added_bytes; From patchwork Thu Dec 22 10:16:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13079564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA36DC4332F for ; Thu, 22 Dec 2022 10:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235301AbiLVKQZ (ORCPT ); Thu, 22 Dec 2022 05:16:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235259AbiLVKQS (ORCPT ); Thu, 22 Dec 2022 05:16:18 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A35765AB for ; Thu, 22 Dec 2022 02:16:17 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4BD6D22431; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=snnrX7j+v4I0SEwzHgq5qUOKMs2mEe8i5HfsO1Rlcpg=; b=2aToEuozG7L2C6QF/uy5gP5d8iTm+PBlnuE6bo+6ahLijSWym4DBCZ/5IWXjWQN6hTjglv uUv5nadRBLF4y+G5tcJZXha3s7cxbq2rYqSHb+25bT+8MCuQkqd/x58b0VBtFCKek+PrrO yOe7XvOKIxZE8rNP5OD7qg5CChKZKWk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671704176; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=snnrX7j+v4I0SEwzHgq5qUOKMs2mEe8i5HfsO1Rlcpg=; b=ORCwr5EgKgb9YKX+F8DLMBZDty7jtfYnA1vj55NleDsWBX85WVMvAFCI2w/zTksuPQfAmi oWNkfEgN11lUtSBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 19A9E13918; Thu, 22 Dec 2022 10:16:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ajM/BnAupGM8WwAAMHmgww (envelope-from ); Thu, 22 Dec 2022 10:16:16 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 2DBA0A0745; Thu, 22 Dec 2022 11:16:12 +0100 (CET) From: Jan Kara To: Cc: Jan Kara Subject: [PATCH 7/7] udf: Keep i_lenExtents consistent with the total length of extents Date: Thu, 22 Dec 2022 11:16:04 +0100 Message-Id: <20221222101612.18814-7-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221222101300.12679-1-jack@suse.cz> References: <20221222101300.12679-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=880; i=jack@suse.cz; h=from:subject; bh=TpB7iJJb9gSlGK+ncASJniTQ93lcdUtZsZwfMOU7G14=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjpC5kXNPENnyKX68ceCjkbTDf6fDearkM/erPGdcJ GsWKuRiJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY6QuZAAKCRCcnaoHP2RA2QwyB/ 0XBZtRCzKyk8xqljOQcrUdgzKTup86uy9BAzOuUxcvjUawzxlOsDweXbyNQlfATWDFcN5iQ89iEKOZ /cFt7D6L1pJDAAZBsvJumkzJxcVbVAcbK1l+6uqhxpjlH9CvwtS2Rq+5O7qAR+4EldWEmQLXwKELqg vJPTmqbVlWom9ewj0tlywThcQpwBz7MUoimttZb7rmjU14YkC7bMT0BQkNDynK4RqmLCl3INbZ7OIH W0b1Dinzb/wlRt0AjLZa/aVrT1ahnuidMhvfqygdH9xnLdii823hkT675P9GAR3GCaDC5/otMDZwCW dXQ7nr9ZXpudHTBhi1JZI0MBBQN76T X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When rounding the last extent to blocksize in inode_getblk() we forgot to update also i_lenExtents to match the new extent length. This inconsistency can later confuse some assertion checks. Signed-off-by: Jan Kara --- fs/udf/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 075e0a9d766c..3621dd7fe5a7 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -677,6 +677,9 @@ static sector_t inode_getblk(struct inode *inode, sector_t block, elen = EXT_RECORDED_ALLOCATED | ((elen + inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1)); + iinfo->i_lenExtents = + ALIGN(iinfo->i_lenExtents, + inode->i_sb->s_blocksize); udf_write_aext(inode, &cur_epos, &eloc, elen, 1); } newblock = udf_get_lb_pblock(inode->i_sb, &eloc, offset);