From patchwork Thu Feb 8 08:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549480 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEBA06A8C0 for ; Thu, 8 Feb 2024 09:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382806; cv=none; b=bz2dlMrvzoEyc2GZpPLLKZ6Ltvzq0e218ZVSUqMPTnBJfHkTJzHzwMD9giCAfJnwHe7NhnexvV6Ble0dAnB2EHk538FUots6F98n18kJ9xewqLDThXVHX3Nqw6bbcJP0JsTuoQjJxRemRwRzW+GZUZ9HrUnyQtc+mseUD8poOFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382806; c=relaxed/simple; bh=6BFobnTFgf00FG+CDK6s6X0AfwAbCXO6VQ3jFLl3yH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R/ldW79rRNHhna9HQkyuiK5I7QFue68z1QxYzLB9UCfTRSA97Gb5aAyvp5vYYm9s1urH7oMdWgZt4x1OiGSor2d2l6wo8ZBYvAa2aPUrxyXvG1Ubb89+giOhoZyZ4V+2mx4YRxYdxV/ZE1wgfKWi9D6lxFfR13cnc5qkqkj9Gpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4DD5721E6F; Thu, 8 Feb 2024 09:00:03 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3CEFE13984; Thu, 8 Feb 2024 09:00:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id aLPeDhOYxGVuDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:03 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 01/14] btrfs: push errors up from add_async_extent() Date: Thu, 8 Feb 2024 09:59:34 +0100 Message-ID: <1ad1e8edabb32fab03aa4d04c61e3cb4be08bb6e.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 4DD5721E6F X-Spam-Flag: NO The memory allocation error in add_async_extent() is not handled properly, return an error and push the BUG_ON to the caller. Handling it there is not trivial so at least make it visible. Signed-off-by: David Sterba --- fs/btrfs/inode.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index adf11936a47e..311d252addaf 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -738,7 +738,8 @@ static noinline int add_async_extent(struct async_chunk *cow, struct async_extent *async_extent; async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS); - BUG_ON(!async_extent); /* -ENOMEM */ + if (!async_extent) + return -ENOMEM; async_extent->start = start; async_extent->ram_size = ram_size; async_extent->compressed_size = compressed_size; @@ -1025,8 +1026,9 @@ static void compress_file_range(struct btrfs_work *work) * The async work queues will take care of doing actual allocation on * disk for these compressed pages, and will submit the bios. */ - add_async_extent(async_chunk, start, total_in, total_compressed, pages, - nr_pages, compress_type); + ret = add_async_extent(async_chunk, start, total_in, total_compressed, pages, + nr_pages, compress_type); + BUG_ON(ret); if (start + total_in < end) { start += total_in; cond_resched(); @@ -1038,8 +1040,9 @@ static void compress_file_range(struct btrfs_work *work) if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) && !inode->prop_compress) inode->flags |= BTRFS_INODE_NOCOMPRESS; cleanup_and_bail_uncompressed: - add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0, - BTRFS_COMPRESS_NONE); + ret = add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0, + BTRFS_COMPRESS_NONE); + BUG_ON(ret); free_pages: if (pages) { for (i = 0; i < nr_pages; i++) { From patchwork Thu Feb 8 08:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549481 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DD186A8C0 for ; Thu, 8 Feb 2024 09:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382809; cv=none; b=Q5xcf3eIDv+rL6W3qQSFHo3b82mGvYDm0rCpdaR22Xvuje6L2r031Gz0eNixwY7aWXWsgRTZR2wjlvgHZAbok/72OEkcgZhQRm+HDtRz3zeJYqO7dVaD+0lIxoeksHXdW/T6eJRzZQ/zICSAJMw1IytfCymtA9E+Q60fCtrHPaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382809; c=relaxed/simple; bh=koup2D07MAt5RqoPap6r7IN9VMaIWPK2R2uFjiDRSXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOJx0n1UAYL8WPeU9tmFkNmp/JCc2ITfzL0gDpQUZUyE5FOpy4xXZHNxOfeQkUUgp3hvn9Y2P3cy5wryZ39iueHI4FAmkOKcxi/YHyhJEHjyBIu4ocWDHnmE7+ldOioUCE6AvS9up2zSwvoT221B96GUp4/vaR0JjjEBbgX7jBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=AxtCsVJF; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=AxtCsVJF; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="AxtCsVJF"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="AxtCsVJF" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A3D641FD56; Thu, 8 Feb 2024 09:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382805; 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=dmKfYjV5uvFZd9t0pe9vnHNet20o12JHwXs3puMGv74=; b=AxtCsVJFfXtZ827Qawz2LwpZRzbl9zI8e3bOkUPj2C+cHvR+LhtDtvB0h3gQp/rOkOEKrB K8vZugMHPpZmurShJ9mNR0uranQmpj55y4auk3aOOY5jNfDybthLRHeoy7C/OhCmKJkt8p Ii/vit3VKlvzlkwI9dA8HZ2+rN0pc54= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382805; 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=dmKfYjV5uvFZd9t0pe9vnHNet20o12JHwXs3puMGv74=; b=AxtCsVJFfXtZ827Qawz2LwpZRzbl9zI8e3bOkUPj2C+cHvR+LhtDtvB0h3gQp/rOkOEKrB K8vZugMHPpZmurShJ9mNR0uranQmpj55y4auk3aOOY5jNfDybthLRHeoy7C/OhCmKJkt8p Ii/vit3VKlvzlkwI9dA8HZ2+rN0pc54= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 930E713984; Thu, 8 Feb 2024 09:00:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id h8blIxWYxGVxDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:05 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 02/14] btrfs: update comment and drop assertion in extent item lookup in find_parent_nodes() Date: Thu, 8 Feb 2024 09:59:36 +0100 Message-ID: <58769dbf1265749659b64af427acc19487c3ae60.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 Same comment was added to this type of error, unify that and drop the assertion as we'd find out quickly that something is wrong after returning -EUCLEAN. Signed-off-by: David Sterba --- fs/btrfs/backref.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index beed7e459dab..0fa27ed802f6 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1435,8 +1435,10 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx, if (ret < 0) goto out; if (ret == 0) { - /* This shouldn't happen, indicates a bug or fs corruption. */ - ASSERT(ret != 0); + /* + * Key with offset -1 found, there would have to exist an extent + * item with such offset, but this is out of the valid range. + */ ret = -EUCLEAN; goto out; } From patchwork Thu Feb 8 08:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549482 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A87BF6BB27 for ; Thu, 8 Feb 2024 09:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382811; cv=none; b=kPNweiaS1jaadvwwM940gw+xFzKRlvQF9YUZPz4q6mRJhBUF35XFHIO0CE/H6vBhiJUU/M4lzgk/cBLCY9Y8Sjr1QAlM9wTFV1ECNXyF4bDx2gTkHUeKLBRIbQMBCiNFe7hr5KE0tyjcxbx7OR99fmDagAZH2amAKdIXfAjLIag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382811; c=relaxed/simple; bh=/8a3K7ZvnboP1/cxfZanwULsuOfhMySOiV+rMn0Vp/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HsXAL6pxkiMjkzKgQtdaH4E4hYrgvY9YpuSMHt7cB6UUlNWQMjvItMjaJiXGgntbamfJh61YylA7sqmahQAoiUtzQekHLh1ezViZb4qSU3pZJrXdfLHLrfu5Rs8Mg4xznGmuimjQrcbko/Bottk1coq5fazUbEs32IGkQg9gaxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=N0exfZB2; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=N0exfZB2; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="N0exfZB2"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="N0exfZB2" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 02E8221E6F; Thu, 8 Feb 2024 09:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382808; 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=nFusZnWuO50spH/oKtAyoeyHJHEufW1YH11UEl9ALYE=; b=N0exfZB2gahlpU3XedqWs/tOR+YsYxBsaW2VoamUdwoZ5cDcY3fmegG5pM39AW7HBmC+KF 97M10PQ4CjBjVBipyhoKgspLtG79fhX2Te0Xp/1g2fGgZzCaB3wo4zIjnYT4EBgXwV8Va3 idwOjY6lYg9kvy7ssK7qLs7p9Ids4rM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382808; 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=nFusZnWuO50spH/oKtAyoeyHJHEufW1YH11UEl9ALYE=; b=N0exfZB2gahlpU3XedqWs/tOR+YsYxBsaW2VoamUdwoZ5cDcY3fmegG5pM39AW7HBmC+KF 97M10PQ4CjBjVBipyhoKgspLtG79fhX2Te0Xp/1g2fGgZzCaB3wo4zIjnYT4EBgXwV8Va3 idwOjY6lYg9kvy7ssK7qLs7p9Ids4rM= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EFCEC13984; Thu, 8 Feb 2024 09:00:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id jJeKOheYxGV0DgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:07 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 03/14] btrfs: handle invalid extent item reference found in extent_from_logical() Date: Thu, 8 Feb 2024 09:59:38 +0100 Message-ID: <6cf0eee9ded5ba3c67265e6b497bf297092bcc0b.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 The extent_from_logical() helper looks up an extent item by a key, allowing to do an inexact search when key->offset is -1. It's never expected to find such item, as it would break the allowed range of a extent item offset. The same error is already handled in btrfs_backref_iter_start() so add a comment for consistency. Signed-off-by: David Sterba --- fs/btrfs/backref.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 0fa27ed802f6..6ba743ddfe21 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -2227,6 +2227,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); if (ret < 0) return ret; + if (ret == 0) { + /* + * Key with offset -1 found, there would have to exist an extent + * item with such offset, but this is out of the valid range. + */ + return -EUCLEAN; + } ret = btrfs_previous_extent_item(extent_root, path, 0); if (ret) { @@ -2870,6 +2877,10 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr) if (ret < 0) return ret; if (ret == 0) { + /* + * Key with offset -1 found, there would have to exist an extent + * item with such offset, but this is out of the valid range. + */ ret = -EUCLEAN; goto release; } From patchwork Thu Feb 8 08:59:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549483 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F48C6A8DD for ; Thu, 8 Feb 2024 09:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382819; cv=none; b=DVywUfVvQ+RuU0UHQHtABimQ3Q1HTyFO1vurMIwbRn3u4CfnWqkquzc7iV/TV3CMYm68iGZiqvduiR/69neHWuTICv+Jn16J/a8tIwk0EH2d2jcQcpezEVbK3w4JuMp9HQkH24sD4794kRYZdEl/Gq4GAn92EGLiEc6WCeYq7E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382819; c=relaxed/simple; bh=T6tUH1yA1Pc7hY5NRIX/F/cOeIksAwqyypLFPixkRw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TVBQ2wHNFjSBvTCb0XweBOWuJclkZJaa7DlP6uyvNvFU/xK7q3KEMRNn8W65HcZ07f6GHZYuTtrkk0Xbo47r1wNzG4RbxJ1Tzh+8q2wuvTa/dHdy0hSY3II3kK+IFvL2/un7biyOdZNXqnkPb/G7amLFBKp9whCAswNkEL2caWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=TZq9uvj1; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=TZq9uvj1; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="TZq9uvj1"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="TZq9uvj1" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 673D421E6F; Thu, 8 Feb 2024 09:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382814; 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=XF/fSJ1XzhKLj4+dOEYNW5wBSo4glcs4lnGFzHki48I=; b=TZq9uvj1EZc9SXsT0YbqpArzLBGoZ9YhTyKCDEmohO3Uvg5FH41njEGXk5/NbzlChtcbd+ b1s6VCcrL6DCZlOP59qIlIkgqEXP/u0BYbMJjeFEMDuDHAwE7gdUN/oayC7zSyBmxIBSIc RtiztndIcQxvYb1risJXJhH3xw0DPz8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382814; 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=XF/fSJ1XzhKLj4+dOEYNW5wBSo4glcs4lnGFzHki48I=; b=TZq9uvj1EZc9SXsT0YbqpArzLBGoZ9YhTyKCDEmohO3Uvg5FH41njEGXk5/NbzlChtcbd+ b1s6VCcrL6DCZlOP59qIlIkgqEXP/u0BYbMJjeFEMDuDHAwE7gdUN/oayC7zSyBmxIBSIc RtiztndIcQxvYb1risJXJhH3xw0DPz8= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5535413984; Thu, 8 Feb 2024 09:00:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id DPXLFB6YxGV4DgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:14 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 04/14] btrfs: handle invalid extent item reference found in find_first_extent_item() Date: Thu, 8 Feb 2024 09:59:41 +0100 Message-ID: <499c884260520b27afcf39f7142ac690ce1b7bc9.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -0.21 X-Spamd-Result: default: False [-0.21 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.11)[-0.574]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO The find_first_extent_item() helper looks up an extent item by a key, allowing to do an inexact search when key->offset is -1. It's never expected to find such item, as it would break the allowed range of a extent item offset. Signed-off-by: David Sterba --- fs/btrfs/scrub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 0123d2728923..c4bd0e60db59 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -1390,8 +1390,15 @@ static int find_first_extent_item(struct btrfs_root *extent_root, ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); if (ret < 0) return ret; + if (ret == 0) { + /* + * Key with offset -1 found, there would have to exist an extent + * item with such offset, but this is out of the valid range. + */ + btrfs_release_path(path); + return -EUCLEAN; + } - ASSERT(ret > 0); /* * Here we intentionally pass 0 as @min_objectid, as there could be * an extent item starting before @search_start. From patchwork Thu Feb 8 08:59:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549484 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 642566BB20 for ; Thu, 8 Feb 2024 09:00:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382820; cv=none; b=EtxHUJ2ziuWV6kkosVYTFZLW89cC0zX59e7pQND8ZromoklfA/q+t99K00q3P3EbOlbUUqXAWlSXVBa3nG0Vz7yJddLBv5MudfM9lDNSQE8GMn9ycJS4tOsOcHHMVqjbLQlx4xTBcgQ9TdBEJWspgL6u/yIqZ8j8d80hk/UMb6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382820; c=relaxed/simple; bh=ITY8picGF6f7/w5JrtPFeQJDxfLmXH6w4pj5CFhNS40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dVQy8qItMMRPVv+tMi6+eRevIxTpx9FftXlVQnlNvfFYH7Lsn/A04UTh5HyYcQw+QcStnCpGTH+fhkm8GZ5SIo0Y5CwWTdPMnxJRLUWrEHK/IZb3GWxLARYzfsxUHajO+MLXqrtaaN1LshaQ3vgRr3qw4xPxVhQSxXvCX3LMnx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B674D21FC8; Thu, 8 Feb 2024 09:00:16 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B0BF113984; Thu, 8 Feb 2024 09:00:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5RAlKyCYxGV9DgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:16 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 05/14] btrfs: handle invalid root reference found in may_destroy_subvol() Date: Thu, 8 Feb 2024 09:59:47 +0100 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: B674D21FC8 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO The may_destroy_subvol() looks up a root by a key, allowing to do an inexact search when key->offset is -1. It's never expected to find such item, as it would break the allowed range of a root id. Signed-off-by: David Sterba --- fs/btrfs/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 311d252addaf..0b36dfb6754b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4389,7 +4389,14 @@ static noinline int may_destroy_subvol(struct btrfs_root *root) ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); if (ret < 0) goto out; - BUG_ON(ret == 0); + if (ret == 0) { + /* + * Key with offset -1 found, there would have to exist a root + * with such id, but this is out of valid range. + */ + ret = -EUCLEAN; + goto out; + } ret = 0; if (path->slots[0] > 0) { From patchwork Thu Feb 8 08:59:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549485 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD6B36BB22 for ; Thu, 8 Feb 2024 09:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382822; cv=none; b=FyoQUAnjMkyfXN6OQo7URJuucQv7uFLHNYLiHmV/wPZNojZNss7kJGA35svH+iUPXjWyjPlg3TvRVNe1ys3fW6fR8DIPr7HtRKCKDsdYOO4C37wsw8Mejnv0lP+/J2ib9rRMc9GZPUWyjELVWJehQ/ySdkH2A+NT+l3w4g9Ob0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382822; c=relaxed/simple; bh=iUJNMX0EYDJtSlzExvNrZBZMD2G58hMuOcXS0NQWW2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tYJ6p6m6ywqWcBVbhE3J19Ul7wzyOgVNjyH+a+Hl5aYKhAZ9cOq1oZHzFGCv7hzkhAo5XdicJZjhX5hoB0X0E3vWUERpRpjIkaV4OZl5MQZoKQq/dVTmnKfY50clLBXi8Ej6bkbaCjxofinebxV6iU/tdKIXDggvDXPiBiXfQbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=U8YCaMtV; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=U8YCaMtV; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="U8YCaMtV"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="U8YCaMtV" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 26BBD21FD4; Thu, 8 Feb 2024 09:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382819; 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=WwaQnfy+CaoMk9iDcwKib1ju4BwihYdtuw0T2ODPtzw=; b=U8YCaMtVIRGvSP7LlhLaitYv5AZz1QtkgirHS9A9SaFjwQk0YjU1BtS0YF7Fqrb7fM5zZW GJyD0f2ZGDhRdQ+vt7xKDM29D7BTqB5zpo2hwhcOp+j5o1BMea95sbL3kHwevAQ5z3lAbh 1llNIIwWeVVyViyLKHpUHP/nBRc7XD0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382819; 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=WwaQnfy+CaoMk9iDcwKib1ju4BwihYdtuw0T2ODPtzw=; b=U8YCaMtVIRGvSP7LlhLaitYv5AZz1QtkgirHS9A9SaFjwQk0YjU1BtS0YF7Fqrb7fM5zZW GJyD0f2ZGDhRdQ+vt7xKDM29D7BTqB5zpo2hwhcOp+j5o1BMea95sbL3kHwevAQ5z3lAbh 1llNIIwWeVVyViyLKHpUHP/nBRc7XD0= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 15ACE13984; Thu, 8 Feb 2024 09:00:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QYtJBSOYxGWBDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:19 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 06/14] btrfs: send: handle unexpected data in header buffer in begin_cmd() Date: Thu, 8 Feb 2024 09:59:50 +0100 Message-ID: <9b3babad8f950d8d3eeba21867782533d4bb1798.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -0.22 X-Spamd-Result: default: False [-0.22 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.11)[-0.574]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[45.55%] X-Spam-Flag: NO Change BUG_ON to a proper error handling in the unlikely case of seeing data when the command is started. This is supposed to be reset when the command is finished (send_cmd, send_encoded_extent). Signed-off-by: David Sterba --- fs/btrfs/send.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 14ea30850739..1bff7b3008ac 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -776,7 +776,12 @@ static int begin_cmd(struct send_ctx *sctx, int cmd) if (WARN_ON(!sctx->send_buf)) return -EINVAL; - BUG_ON(sctx->send_size); + if (unlikely(sctx->send_size != 0)) { + btrfs_err(sctx->send_root->fs_info, + "send: command header buffer not empty cmd %d offset %llu", + cmd, sctx->send_off); + return -EINVAL; + } sctx->send_size += sizeof(*hdr); hdr = (struct btrfs_cmd_header *)sctx->send_buf; From patchwork Thu Feb 8 08:59:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549486 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D4C56BB43 for ; Thu, 8 Feb 2024 09:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382824; cv=none; b=XPHK5RYZmOgBE0sF1u+hpy7G+T96zVNR8Yg/iYVh4JZPwfzE4aM6FTL5YdGwljtj09uPO+feCcKIAIIbFvdGR6+ATz36aV4ZlEbkaxtSfWpWhlrJdNRohn96bEDqcQSkKcmLPzm2Hl36gOshXc1bXbknCtScl5QI495i9UjfyUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382824; c=relaxed/simple; bh=t5Rew0KgMAWJQQMa/j+/uTowJI6KBir7v1ZjKg3wrCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMPJRPf5yn6r/4wQr+zul9LvECmcnjT8bh7lT73jiqNrQ9PiOD+3GUCzqa43zJbF7e7VlCTJbP9HmAMDBG0fcYvWANpiVkkR6YZpLQ2w6EKej6si/2+CwnlHMKjXOlYTHD2DTOSDRpDQP4d0yywlDRdHPvEIrrddfTCq92shwfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ByBcxR3i; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ByBcxR3i; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ByBcxR3i"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ByBcxR3i" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 73A2A21E6F; Thu, 8 Feb 2024 09:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382821; 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=zrRuhIx9KB22j+ieuDI+ZtvxzBHp7f17r4pLGRJRUvg=; b=ByBcxR3i4ghLLlhdbTAN8/REcJWqW/24/tk4YcV/h9RvjFd4b0wsTlxbZ25/bQVOCvMBTB +ldecmrFYMWD1Zbj0vpzv2EtqVtq67nsWCcvEA+AgII4hBSm0Tw4ZEQ2jJC0XfUT7CCWAU GGAc8lGKMT7Z1odk9fWSIbW8YS3M1M8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382821; 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=zrRuhIx9KB22j+ieuDI+ZtvxzBHp7f17r4pLGRJRUvg=; b=ByBcxR3i4ghLLlhdbTAN8/REcJWqW/24/tk4YcV/h9RvjFd4b0wsTlxbZ25/bQVOCvMBTB +ldecmrFYMWD1Zbj0vpzv2EtqVtq67nsWCcvEA+AgII4hBSm0Tw4ZEQ2jJC0XfUT7CCWAU GGAc8lGKMT7Z1odk9fWSIbW8YS3M1M8= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6DE3C13984; Thu, 8 Feb 2024 09:00:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6wTRGiWYxGWGDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:21 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 07/14] btrfs: send: handle unexpected inode in header process_recorded_refs() Date: Thu, 8 Feb 2024 09:59:52 +0100 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[42.88%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 Change BUG_ON to proper error handling when an unexpected inode number is encountered. As the comment says this should never happen. Signed-off-by: David Sterba --- fs/btrfs/send.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 1bff7b3008ac..778c2da1c9dd 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -4186,7 +4186,13 @@ static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) * This should never happen as the root dir always has the same ref * which is always '..' */ - BUG_ON(sctx->cur_ino <= BTRFS_FIRST_FREE_OBJECTID); + if (unlikely(sctx->cur_ino <= BTRFS_FIRST_FREE_OBJECTID)) { + btrfs_err(fs_info, + "send: unexpected inode %llu in process_recorded_refs()", + sctx->cur_ino); + ret = -EINVAL; + goto out; + } valid_path = fs_path_alloc(); if (!valid_path) { From patchwork Thu Feb 8 08:59:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549487 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89D416BB50 for ; Thu, 8 Feb 2024 09:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382828; cv=none; b=Dtyyg6jME1bYXz3njgvBD+V9feWAKIJqU/FYJeWwIN4PoewVBo+Vf3Z8X67b6ectBeUOHNlJaGBcyCCvRnH6Y46Nwnwv8r+IH/SZF4d3xE08QBw+cG8j8urgKPCrJNLC0/dYXLMQkhrYlWqfcZ+nl81PezlQRfNA5wBNymMcXPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382828; c=relaxed/simple; bh=UjsKkUOPOeMEsx7zy4oYMtKpQlPAPHEjLEXkgcajYyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZlwRSaHYGjjD8Z6wiBEPBKrpXyAyr92Us1QCoZ+I8xD1FoTSxyE1hhB+/0KIxjXCAjQ6Q6wK8Fy3v8TRUzxrdozsYtIcP9o5n4D06N/+lLIy6R+Rx/NBe7w6LutL2bMnxuB8Fq4jnezA2KsV3kVyIh7V5oVs8obKaHi3O7UYBtc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D498A21FFB; Thu, 8 Feb 2024 09:00:23 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C41DD13984; Thu, 8 Feb 2024 09:00:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8OvfLyeYxGWIDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:23 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 08/14] btrfs: send: handle path ref underflow in header iterate_inode_ref() Date: Thu, 8 Feb 2024 09:59:54 +0100 Message-ID: <1ec6f2454ec18dcc36d60f8b39361f5dd1d97d5e.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: D498A21FFB X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO Change BUG_ON to proper error handling if building the path buffer fails. The pointers are not printed so we don't accidentally leak kernel addresses. Signed-off-by: David Sterba --- fs/btrfs/send.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 778c2da1c9dd..7a601de7fa7c 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1074,7 +1074,15 @@ static int iterate_inode_ref(struct btrfs_root *root, struct btrfs_path *path, ret = PTR_ERR(start); goto out; } - BUG_ON(start < p->buf); + if (unlikely(start < p->buf)) { + btrfs_err(root->fs_info, + "send: path ref buffer underflow for key (%llu %u %llu)", + found_key->objectid, + found_key->type, + found_key->offset); + ret = -EINVAL; + goto out; + } } p->start = start; } else { From patchwork Thu Feb 8 08:59:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549488 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC2E6A35B for ; Thu, 8 Feb 2024 09:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382829; cv=none; b=bOZyYCrId+cN6TU5PBaQc71D4vYscdzMLe3ujhh0ZbJwuPdl+2VlXUD6f8NG5WGs/2vea6pawvJEfArL+gpRUfgccNBCCm8owmJfS+n/ynXnzyKYwR3PDwsErTB9GOEUrmXz2wVmAsL69wqwQL+x4lXk0ccpjbCNumUnY8+pJ4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382829; c=relaxed/simple; bh=cjg9Y4ZcCQEO3Rn1hc2vP+XTr7NF+vYWh6Y1jbXCTmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+LxPMjQhia0WQTa8r50EJXtHtiVOk9njjcc79lnJqaQb4iHNNAcKnslLOgjI33hten+2dD/e1idlbLaK59r/iqeIhpUTLgeP5XBdHGy5ArqhkRyEKwTBhSio/cwRGuTyKSrTuu/i+lvzpxKiQD6UwZBGPDNnIWCb7wVzdMGlEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 342A31FD56; Thu, 8 Feb 2024 09:00:26 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2EB9513984; Thu, 8 Feb 2024 09:00:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Ra9mCyqYxGWMDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:26 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 09/14] btrfs: change BUG_ON to assertion in tree_move_down() Date: Thu, 8 Feb 2024 09:59:57 +0100 Message-ID: <513e4f7646b52d79f2bf37eaafc39c9cd074a475.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 342A31FD56 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO There's only one caller of tree_move_down() that does not pass level 0 so the assertion is better suited here. Signed-off-by: David Sterba --- fs/btrfs/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 7a601de7fa7c..e96d511f9dd9 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -7438,8 +7438,8 @@ static int tree_move_down(struct btrfs_path *path, int *level, u64 reada_min_gen u64 reada_done = 0; lockdep_assert_held_read(&parent->fs_info->commit_root_sem); + ASSERT(*level != 0); - BUG_ON(*level == 0); eb = btrfs_read_node_slot(parent, slot); if (IS_ERR(eb)) return PTR_ERR(eb); From patchwork Thu Feb 8 08:59:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549489 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D37A69E1E for ; Thu, 8 Feb 2024 09:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382836; cv=none; b=RvaHflfEXkFmqt5SiONnfmb/fuCG2+N/OeT5zuLrNU97ki5i3EnxAtU/6Z/kojeQEpj7JJzFx3O9rKY+1P/4YgEI3f+vcDP4m/8JpnLls7ef5C2P2dA6Ij99DgQsQS3yk//fCqdtSd7+HlK0Dbd8STC1+IlzqBB8LfcyAhp6s9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382836; c=relaxed/simple; bh=A/ZsPrXigPkg4aU6eyufkVANTx8f+mBR8IBVdhKifdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZgSZR1PfVmpJEcRf/0Js1XrlaYTAy9HQnKdqlF2Yn3bE48iKceeMEXEMjxnE+Txu9HYPgv+eRga+NvqdsfsuhJEyIejqvFKDHyPnWKaliXnQbUiJjTEKwPkpsSau42bOQT9KLV31dgMHeA8UolOPfPKePP+EEgylw0bHX9klgGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ukdVWxs+; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ukdVWxs+; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ukdVWxs+"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ukdVWxs+" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8C9AB1FD4F; Thu, 8 Feb 2024 09:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382832; 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=NHaUWbHuCE4XPMHWcOIlrQp6LAFSDbmykNs1Sjt4u94=; b=ukdVWxs+3AYDFucQ4wiJdkUyePJ8IPNY+NIZuEONTOYndzZ22DrnxG3/cy4K83dtolZa+H 5Aec69tyI5iC2GCiqZX/VGgDsccIJO8MqYk0H7mJQQ2j/BhA1JfNUUXFEXm1ABzynVKAdA 2QXyBvYvfNmscB6aUs813YYEVuCW8aM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382832; 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=NHaUWbHuCE4XPMHWcOIlrQp6LAFSDbmykNs1Sjt4u94=; b=ukdVWxs+3AYDFucQ4wiJdkUyePJ8IPNY+NIZuEONTOYndzZ22DrnxG3/cy4K83dtolZa+H 5Aec69tyI5iC2GCiqZX/VGgDsccIJO8MqYk0H7mJQQ2j/BhA1JfNUUXFEXm1ABzynVKAdA 2QXyBvYvfNmscB6aUs813YYEVuCW8aM= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 868DE13984; Thu, 8 Feb 2024 09:00:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id DCXaIDCYxGWWDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:32 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 10/14] btrfs: change BUG_ONs to assertions in btrfs_qgroup_trace_subtree() Date: Thu, 8 Feb 2024 09:59:59 +0100 Message-ID: <3a8d00bf5a842f4d54986834be0755386b88529c.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.22 X-Spamd-Result: default: False [-0.22 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.12)[-0.581]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO The only caller do_walk_down() of btrfs_qgroup_trace_subtree() validates the value of level and uses it several times before it's passed as an argument. Same for root_eb that's called 'next' in the caller. Change both BUG_ONs to assertions as this is to assure proper interface use rather than real errors. Signed-off-by: David Sterba --- fs/btrfs/qgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 5470e1cdf10c..cfe366110a69 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2505,8 +2505,8 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans, struct extent_buffer *eb = root_eb; struct btrfs_path *path = NULL; - BUG_ON(root_level < 0 || root_level >= BTRFS_MAX_LEVEL); - BUG_ON(root_eb == NULL); + ASSERT(0 <= root_level && root_level < BTRFS_MAX_LEVEL); + ASSERT(root_eb != NULL); if (!btrfs_qgroup_full_accounting(fs_info)) return 0; From patchwork Thu Feb 8 09:00:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549490 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6AD96A8DE for ; Thu, 8 Feb 2024 09:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382838; cv=none; b=RRv/t2h3M/cFC41ZhpbxzO7vG4/PdRW+qiIBfvrk+sH7yvhTggxjs04bo3S7MqPy/0A/wvvGcUXRfQiWLMYmufRC7W05yRAJd7aztKlmEIUTmofPKeFG7HhlM8tdIittuzm7YFRAMuEUA2IuV0DMO+3ilrpgQSu2qaH9tO9htRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382838; c=relaxed/simple; bh=QQVO7uW1K/XHBpwekwLsjqwTJXByWfcAqUUUqs92U64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iooNo3ZCaQOOu6ww5KyBr3/yeQgW5+ijBjUaQH7WatqKKa21EeQ2XXRcCxeCoHuWW8CD7zAe4wNJs+qpWboKzorf76i2jkbokyBtw35ypAHZaH4o9W+IaQyEMCknkUwbkO7LUlWGXLRGtjo8prJqs28tI6XorQtoVMzUZOECaD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=jYDqBWH0; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=VyX+H5U/; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="jYDqBWH0"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="VyX+H5U/" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ECC7521E6F; Thu, 8 Feb 2024 09:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382835; 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=U25kFUxDqTV5JiVLj17jbn2cCY3xwNzdsVCkmVUgiN0=; b=jYDqBWH0FujCNBbxJ7pmSvXwBAmKLMbdCEAaZFSF7NUogOuzILnNyv3C3JNiDUrjnGdWZ7 yeNXHA6OHWvInVCKoZy0XBrrRCqOT0db7YaXEh2ppeWWLy0LXnoQs+6dOatA/GBXAZAsLp kYEK2N/wAoXFhbMuO8gAUp63LWB+Kzc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382834; 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=U25kFUxDqTV5JiVLj17jbn2cCY3xwNzdsVCkmVUgiN0=; b=VyX+H5U/JHhBJDztOOZL7KMA73TG+yh0vHmHFhYZQ/loJD8BYGga5zKkhlRx8dJLsLA06V NpbTKasT/H8GVCw68w6iAs4MEWHvaUYWoho6+X9i0fx7mWYhetfdp5usc2sZEE7GdYjzWw 2L3DV/BXWjRgVTMqnl3nDmfCojEFFNQ= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E65C913984; Thu, 8 Feb 2024 09:00:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id LM06ODKYxGWdDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:34 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 11/14] btrfs: delete pointless BUG_ON check on quota root in btrfs_qgroup_account_extent() Date: Thu, 8 Feb 2024 10:00:05 +0100 Message-ID: <2099237fb84081f127961edffa18aabccefc9799.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[17.24%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 The BUG_ON is deep in the qgroup code where we can expect that it exists. A NULL pointer would cause a crash. It was added long ago in 550d7a2ed5db35 ("btrfs: qgroup: Add new qgroup calculation function btrfs_qgroup_account_extents()."). It maybe made sense back then as the quota enable/disable state machine was not that robust as it is nowadays, so we can just delete it. Signed-off-by: David Sterba --- fs/btrfs/qgroup.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index cfe366110a69..044331228bd0 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2861,8 +2861,6 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr, if (nr_old_roots == 0 && nr_new_roots == 0) goto out_free; - BUG_ON(!fs_info->quota_root); - trace_btrfs_qgroup_account_extent(fs_info, trans->transid, bytenr, num_bytes, nr_old_roots, nr_new_roots); From patchwork Thu Feb 8 09:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549491 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 244EA6BB50 for ; Thu, 8 Feb 2024 09:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382840; cv=none; b=UrxX/013r2IVQ/iN/XlUp5DSnXVHi1Ry0SfYIOtjUpLvPw6qDMiiGvgJb02bK1zu3Xl6p1qmOdL3jVvSSfXWecIjR4NHGS3ERRXGtuO7j5Gl1mDrDqQsokm4loYI++W9iDjTcPYaiPuTVdxVTOAH0SkxrSn+6BDFg76ZBibo+P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382840; c=relaxed/simple; bh=L1Zhviyoxyid7j3hZCgaAyQWQfYRW8zNQLlbMeXD77A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ibwS3UL5BSaJWHeVY40LdljrrPgbKTG2KMlJwj+XVzAlqfz8xwSi//WANEBR5czYSISNzK13c2rwAlr4eliebPDEGgIxGZ55tSU5huteiZMgXkP5TxgIDI6SoUNk0IShLi+HDVZEPHwwAzWhRkgB9ZIWkStpPnG2kRW/RjKEeFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=grOpH0YB; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=grOpH0YB; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="grOpH0YB"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="grOpH0YB" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5B6AA21F56; Thu, 8 Feb 2024 09:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382837; 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=bxnKIKz2V+2h7wI8MfcazmX6it3PrKqFLEUAA5ITVSI=; b=grOpH0YB3UnwfKQV/UBtsO8/eAMkxoJfru8iDx+iDNYwOIVHMzS0/R/3NXf3LzOI7xUf5t dhVF2fvywmdOQoXojnfK0/TvgVKIjol/MXgRKxG7CSI5zhYreaM2TzaHMkwKzWOku9LkKS eTzulb8jG2+5Sf0JnXUBHjbPGt/5z+o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382837; 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=bxnKIKz2V+2h7wI8MfcazmX6it3PrKqFLEUAA5ITVSI=; b=grOpH0YB3UnwfKQV/UBtsO8/eAMkxoJfru8iDx+iDNYwOIVHMzS0/R/3NXf3LzOI7xUf5t dhVF2fvywmdOQoXojnfK0/TvgVKIjol/MXgRKxG7CSI5zhYreaM2TzaHMkwKzWOku9LkKS eTzulb8jG2+5Sf0JnXUBHjbPGt/5z+o= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4AAF313984; Thu, 8 Feb 2024 09:00:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id mws6EjWYxGWnDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:37 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 12/14] btrfs: delete pointless BUG_ONs on extent item size Date: Thu, 8 Feb 2024 10:00:08 +0100 Message-ID: <8c4bfd140e6ad04a46ce0a3774c33723931e98ad.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[20.88%] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 Checking extent item size in add_inline_refs() is redundant, we do that already in tree-checker after reading the extent buffer and it won't change under normal circumstances. It was added long ago in 8da6d5815c592b ("Btrfs: added btrfs_find_all_roots()") and does not seem to have a clear purpose. Similar case in extent_from_logical(), added in a542ad1bafc7df ("btrfs: added helper functions to iterate backrefs"). Signed-off-by: David Sterba --- fs/btrfs/backref.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 6ba743ddfe21..fe05e2f55bf7 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1036,8 +1036,6 @@ static int add_inline_refs(struct btrfs_backref_walk_ctx *ctx, slot = path->slots[0]; item_size = btrfs_item_size(leaf, slot); - BUG_ON(item_size < sizeof(*ei)); - ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); if (ctx->check_extent_item) { @@ -2256,7 +2254,6 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, eb = path->nodes[0]; item_size = btrfs_item_size(eb, path->slots[0]); - BUG_ON(item_size < sizeof(*ei)); ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item); flags = btrfs_extent_flags(eb, ei); From patchwork Thu Feb 8 09:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549492 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A56E6BFA9 for ; Thu, 8 Feb 2024 09:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382842; cv=none; b=ZW/yyu1Yzjs68dh/6jxDElna6NVaRx9EJFDj1/jB06SLNILcUnHFf5R+3Z0ZuDoQpffNjLwqs//xmN6z8YjyLDNSZw2eenDyuhvIU0E6T0CW4C1r0OXinCM9KBUtiIfaWDPijKTgN7Aok2HMI1qzR4LJwsFKOXEJpxKXS4YQWLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382842; c=relaxed/simple; bh=6i4adDmcjAEF0lPe6PDGE+HTk1kYibUyDWk6ObIGKyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pHUGBUsUg+S7qELZsWnZz8ZE/k3u8Rgn4Ov1/U9kpO2Cq7Hk2CbkkjEioDKKQZxC3n2Dzsg0RPEvroiZAZAIiU90e9YNeBX+f5IC/RIoh4KFe2HuPChh5P4Qd9LxujEm3a9ALiw3yoM2+YT0Y5v9fRddEYmbyp+diisHBfFOAvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AB72621E6F; Thu, 8 Feb 2024 09:00:39 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A4C6C13984; Thu, 8 Feb 2024 09:00:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id bOE5KDeYxGWqDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:39 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 13/14] btrfs: handle unexpected parent block offset in btrfs_alloc_tree_block() Date: Thu, 8 Feb 2024 10:00:10 +0100 Message-ID: <89b72a65f0b33c1fee65d6b945d5e9c29e799318.1707382595.git.dsterba@suse.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: AB72621E6F X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO Change a BUG_ON to a proper error handling, here it checks that a root other than reloc tree does not see a non-zero offset. This is set by btrfs_force_cow_block() and is a special case so the check makes sure it's not accidentally set by other callers. Signed-off-by: David Sterba --- fs/btrfs/extent-tree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0d72d0f7cefc..3708f886d21a 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5187,8 +5187,16 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, parent = ins.objectid; flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF; owning_root = reloc_src_root; - } else - BUG_ON(parent > 0); + } else { + if (unlikely(parent > 0)) { + /* + * Other roots than reloc tree don't expect start + * offset of a parent block. + */ + ret = -EUCLEAN; + goto out_free_reserved; + } + } if (root_objectid != BTRFS_TREE_LOG_OBJECTID) { extent_op = btrfs_alloc_delayed_extent_op(); From patchwork Thu Feb 8 09:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 13549493 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1E6E6BFAB for ; Thu, 8 Feb 2024 09:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382845; cv=none; b=n30w80AYYxPZeL405NX73n3mQPqzbeTyHYRA6HbL9ZkLekcNwQn9a7u+NUvSbIkuT0Rh7EyRYpFg07r8M/+Jk57Kjq6YLI05SF035CgPhPaBJYdt1wn0hQDlUQ8nJek4uJmS2dJEL4ExBuWzQ1h3D2pLB71+G4J5dyTpQb/cWmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707382845; c=relaxed/simple; bh=IY3Dkrkswuk1H7TJCTzi9fv1K7X3TZmGI8UpoW1cBQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M+7VceDSXodbvJPfgVv9IgKLN6tc3vpZlE/1u6w8R0idwYy7XhmzlIAsHOTn2tj4yaRZaOenqn15+iSmTd1Kcsmr7LMp4taNs/xqP0trQKqd3bJFdJspzoBTrXP4QFW4/ZFCokigRyBiVpUBh0tspaTJc/wZCBuVQB/6bU0b0pY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=KQP9+zQi; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=KQP9+zQi; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="KQP9+zQi"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="KQP9+zQi" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 131071FD4F; Thu, 8 Feb 2024 09:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382842; 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=5yyr3+9zdtU3F9hkizAZQPs9PeNcynm3z5utlilt8IU=; b=KQP9+zQigyltSRzr6w/3Zotdw1VMEg9r+XoQcA0POANJcAM6yUbmhHxNrfLwI9hTf7iUvQ +7WLakNVPyh33wbnvHrNYt3mJ1EDgLfAO7jp5qQ0nMueeTBRguKKz3GPKwDQ3ywfCk5ll2 IEJmHknoblwNMpYply6bqlPPz6bDI8M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1707382842; 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=5yyr3+9zdtU3F9hkizAZQPs9PeNcynm3z5utlilt8IU=; b=KQP9+zQigyltSRzr6w/3Zotdw1VMEg9r+XoQcA0POANJcAM6yUbmhHxNrfLwI9hTf7iUvQ +7WLakNVPyh33wbnvHrNYt3mJ1EDgLfAO7jp5qQ0nMueeTBRguKKz3GPKwDQ3ywfCk5ll2 IEJmHknoblwNMpYply6bqlPPz6bDI8M= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0B77813984; Thu, 8 Feb 2024 09:00:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sN7KAjqYxGWxDgAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 09:00:42 +0000 From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 14/14] btrfs: delete BUG_ON in btrfs_init_locked_inode() Date: Thu, 8 Feb 2024 10:00:13 +0100 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: 0.90 The purpose of the BUG_ON is not clear. The helper btrfs_grab_root() could return a NULL in case args->root would be a NULL or if there are zero references. Then we check if the root pointer stored in the inode still exists. The whole call chain is for iget: btrfs_iget btrfs_iget_path btrfs_iget_locked iget5_locked btrfs_init_locked_inode which is called from many contexts where we the root pointer is used and we can safely assume has enough references. Signed-off-by: David Sterba --- fs/btrfs/inode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0b36dfb6754b..459ec9ba06e0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5548,7 +5548,6 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p) BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY; BTRFS_I(inode)->location.offset = 0; BTRFS_I(inode)->root = btrfs_grab_root(args->root); - BUG_ON(args->root && !BTRFS_I(inode)->root); if (args->root && args->root == args->root->fs_info->tree_root && args->ino != BTRFS_BTREE_INODE_OBJECTID)