From mboxrd@z Thu Jan 1 00:00:00 1970 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 550AFC77B7A for ; Wed, 31 May 2023 13:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236995AbjEaNtX (ORCPT ); Wed, 31 May 2023 09:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237007AbjEaNsr (ORCPT ); Wed, 31 May 2023 09:48:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E934CE41; Wed, 31 May 2023 06:44:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 552E863B47; Wed, 31 May 2023 13:43:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CA3CC433EF; Wed, 31 May 2023 13:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685540619; bh=Vvji4uh0s4T1YrkOa9+Z9ZOuG3eJAbPAuPjElVTyO2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0VD+4Fbc7wDXNTddmtc7ge81tzpf278+N5D5eWJVJtrS8qeYIJH/FVONz6MdPaO6 a1fhEIE5tgZERykDy5Lc1KBzDqPzxtX53/DFozxI0m9ZeOoJeV29YTCjJjcThmv07e rTMx99AoyLCe1ssztvVimGu+6uPcP+slcP4xyOQ2t89Uk06Xhrc+YjGfOn66E97nfH FbRliX/bHIKJHHVJwzOIU4esMW8rWdOFuNTAiM60ST39UkEXMUo/Wyl3ZV0/8sl0ww LQcqipU0bmkA3i8AKz9hhSSegB3BcRvnGHIq5Z9mn7UPhQ/0FmufJimhiOOUsU0yVb t7/EEPcsI1c9A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Johannes Thumshirn , syzbot+d8941552e21eac774778@syzkaller.appspotmail.com, Christoph Hellwig , Anand Jain , David Sterba , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 13/24] btrfs: handle memory allocation failure in btrfs_csum_one_bio Date: Wed, 31 May 2023 09:43:09 -0400 Message-Id: <20230531134320.3384102-13-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531134320.3384102-1-sashal@kernel.org> References: <20230531134320.3384102-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Johannes Thumshirn [ Upstream commit 806570c0bb7b4847828c22c4934fcf2dc8fc572f ] Since f8a53bb58ec7 ("btrfs: handle checksum generation in the storage layer") the failures of btrfs_csum_one_bio() are handled via bio_end_io(). This means, we can return BLK_STS_RESOURCE from btrfs_csum_one_bio() in case the allocation of the ordered sums fails. This also fixes a syzkaller report, where injecting a failure into the kvzalloc() call results in a BUG_ON(). Reported-by: syzbot+d8941552e21eac774778@syzkaller.appspotmail.com Reviewed-by: Christoph Hellwig Reviewed-by: Anand Jain Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file-item.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index dd8b02a2a14a0..4c210b2ac6994 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -700,7 +700,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio, sums = kvzalloc(btrfs_ordered_sum_size(fs_info, bytes_left), GFP_KERNEL); memalloc_nofs_restore(nofs_flag); - BUG_ON(!sums); /* -ENOMEM */ + if (!sums) + return BLK_STS_RESOURCE; + sums->len = bytes_left; ordered = btrfs_lookup_ordered_extent(inode, offset); -- 2.39.2