From patchwork Wed Nov 9 18:14:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 17730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp488864wru; Wed, 9 Nov 2022 10:17:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf63ScQGoyfA6qynqg2TydKsuQtfzua1E1sTn/bfZzmnXB8wibaFgYYl4h3f5xMoMyGZCo84 X-Received: by 2002:a17:902:cf07:b0:188:7e83:c5f1 with SMTP id i7-20020a170902cf0700b001887e83c5f1mr17991462plg.58.1668017830016; Wed, 09 Nov 2022 10:17:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668017830; cv=none; d=google.com; s=arc-20160816; b=qWZz0x/qst+8JkxnXtRtUmy10HciuR8IrGuDY9XRSoybtBy3JhqVaV+jWn0695r4Pd K/004DWny7/fH4kbPbHaQOPpdCnrSz7Jx7POuaLIEoiXgxB8VpU1dc0QJsS1jA+J7oO3 WVGw7iFPvlr/nE7Sz6h4sKgdWTl0GIKVI3ju8+EltINeCemgOSu8HbHmNX2gcirBth9a imioVrstxVzV5iC8AtNFPukqsOa/IqGu/l0D74t+VaEdgywn75lB/dybTmrwZsFUReQQ YY8ZQQS0YQDaz5ne0rMHVCoZrsGZt4MXYuduuCxEbU2Fo2OaAeq9N5eYjdO3iHPm4NdD Y0Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=rY7W3z7DqhCLcEiGD9R5jcYRT8wjZ5iw0Oyp7Ha8n98=; b=jhggmIAWNclyeOB9Yg/0gXaN2ZSFs3T8X5wV+dgGDRLSsjsO+O3RqdJdOEhk8WWCE3 /HsaoXwdRn+xRw83m7ineWPy1L6l5Ob1ei1kBmAHaHXFasZKj3x28CCeSJPzE4XNkYzz MURWkQDyhma62n3k/d8qEtLyyiM0UbCTuyNjuzwNF7mAWkhfx5c8SZcKxzyRRyObXEyJ UVwzIuMb1zF9UIzXnaiBbLb8X17k1trDSgGZk1E4xiLA0KHnbCAXXN+r2haq+Eoejs91 LnUgoSQ10KEddPQlrK9j6kcloI2FKZ9uqjcQA1L+Hh0q3X/t0/5yR5p6mupTrHQ22jxp xD9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="ea0Vp/PY"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020a170902b58d00b00177fd8409b7si16626701pls.73.2022.11.09.10.16.56; Wed, 09 Nov 2022 10:17:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="ea0Vp/PY"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbiKISNu (ORCPT + 99 others); Wed, 9 Nov 2022 13:13:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiKISNs (ORCPT ); Wed, 9 Nov 2022 13:13:48 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFEC61005F; Wed, 9 Nov 2022 10:13:47 -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 7FD4621A0A; Wed, 9 Nov 2022 18:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1668017626; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rY7W3z7DqhCLcEiGD9R5jcYRT8wjZ5iw0Oyp7Ha8n98=; b=ea0Vp/PYeoE/mBbxngpWZ10yYt4E82F3m+2ZMQm8RS7oCm5mKTFa0qp7gR01SsjCOgQQSk ptnoQQa+RlrPM5II7eRY5j59hSph7nTNWa/fFzG5KV64YLaP2bkNCpQjLTwRGODH0usjaO Aae6LkEjajvbJKpdWyvs/ItmGbIMdX4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1668017626; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rY7W3z7DqhCLcEiGD9R5jcYRT8wjZ5iw0Oyp7Ha8n98=; b=UhSDuGSnSRRm53jENn+yRKiTW7xZrSDl1emZHpFVzdUKQwaIIIsGI6XbUM8MmIZ70sh9lg RJTeVvL6mnb/t0CQ== 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 2B0731331F; Wed, 9 Nov 2022 18:13:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EyS6B9rta2PbKgAAMHmgww (envelope-from ); Wed, 09 Nov 2022 18:13:46 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id cc02a9da; Wed, 9 Nov 2022 18:14:46 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: "Theodore Ts'o" , Andreas Dilger Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= Subject: [PATCH] ext4: fix error code return to user-space in ext4_get_branch() Date: Wed, 9 Nov 2022 18:14:45 +0000 Message-Id: <20221109181445.17843-1-lhenriques@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749043464337269821?= X-GMAIL-MSGID: =?utf-8?q?1749043464337269821?= If a block is out of range in ext4_get_branch(), -ENOMEM will be returned to user-space. Obviously, this error code isn't really useful. This patch fixes it by making sure the right error code (-EFSCORRUPTED) is propagated to user-space. EUCLEAN is more informative than ENOMEM. Signed-off-by: Luís Henriques --- Hi Ted! Just a note: this patch, as you suggested, is taken from the patch with message-id 20221011155623.14840-1-lhenriques@suse.de . Cheers, -- Luís fs/ext4/indirect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 860fc5119009..c68bebe7ff4b 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -148,6 +148,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, struct super_block *sb = inode->i_sb; Indirect *p = chain; struct buffer_head *bh; + unsigned int key; int ret = -EIO; *err = 0; @@ -156,7 +157,13 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth, if (!p->key) goto no_block; while (--depth) { - bh = sb_getblk(sb, le32_to_cpu(p->key)); + key = le32_to_cpu(p->key); + if (key > ext4_blocks_count(EXT4_SB(sb)->s_es)) { + /* the block was out of range */ + ret = -EFSCORRUPTED; + goto failure; + } + bh = sb_getblk(sb, key); if (unlikely(!bh)) { ret = -ENOMEM; goto failure;