Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3180952rdb; Tue, 26 Dec 2023 21:06:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdywd9vKYUN/CKOJMLOjrsk9oT0vX2wGukR98H0MZN3HPZy9sPaVTuKsGLIoIwmdJ75Ob9 X-Received: by 2002:ac8:5bd2:0:b0:427:7c4f:9d1c with SMTP id b18-20020ac85bd2000000b004277c4f9d1cmr12214699qtb.61.1703653618354; Tue, 26 Dec 2023 21:06:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703653618; cv=none; d=google.com; s=arc-20160816; b=fXeoSnP5+uFg++U161kT/SrE5ZZXasxTTxR0vZByjmUIuE7O3kIl2U8fFsw+3FkfRR qx8G5ZDQVddETW4/8wTaQa/bcMKQCWRjCVQyOwX3nHNp9xN2htG9MnRHv5VXUYLzOEHq 3EoOsVhkh3SaTg+AzbzKhExSrUFQ953TT88yVj0YoQvKu5gZTkHApTAlkq3UK96H8KQl LiHS5NUete+OSS+qlcDTAagfGKf8T1o6ffkxdmmRsyd9QU6JHE9g3r6XG4+xm69XJFZF BMfjHKduFWQxJjyDI3MEUVFI4MLn/AusCZXynBs//RoYwcopGepaynClyCnnk8knRYck mCyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=waH96jtLfxIiU1DP/vUgKAGPYaGonG2jMRmx6lpDNTw=; fh=bnrnBcbyx0sM9DAnoHOQn6e7uer82WeSGox/oq7y2Ak=; b=DrM4FL0dKB2PANsKiMGNeVQ3YMyYRSszZnlCGZgUwgyx+KSeKwQLkSPz1xX3SX9MJg H68FqeAAOuOohQMt3n4MW0at1xdzdTCOYEd76iG+vEeyMqkWKdGHrMOnvhpygJuwTpPQ EzgAalg46hfVylwP74mIpQIzkE1xFy0Iu4uk5CqL+QohIBYbd1XLVHVvsy4QS7d+jlJF xdRg7aX5DRJ80Ci6pl0F3WqMHWuTRSg6mF6+6fiFBX4u4dk40zs1acxaLpZpQzPQNfGB bgAuRN2lRjZbmq7kiQhPfHUCSZNXomWPVubq8rfCQTr3xfVhASpcAkR4GGEBDm1eqHfn 8MHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e15-20020a05622a110f00b00423a2b349b6si14174916qty.346.2023.12.26.21.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 21:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 153EF1C20BFA for ; Wed, 27 Dec 2023 05:06:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E3E53FF4; Wed, 27 Dec 2023 05:06:51 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA4A3C24 for ; Wed, 27 Dec 2023 05:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R791e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VzJx.pC_1703653594; Received: from e69b19392.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VzJx.pC_1703653594) by smtp.aliyun-inc.com; Wed, 27 Dec 2023 13:06:39 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Yue Hu Cc: LKML , Chao Yu , Gao Xiang , bugreport@ubisectech.com Subject: [PATCH v2] erofs: fix inconsistent per-file compression format Date: Wed, 27 Dec 2023 13:06:33 +0800 Message-Id: <20231227050633.1507448-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231227041718.1428868-1-hsiangkao@linux.alibaba.com> References: <20231227041718.1428868-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit EROFS can select compression algorithms on a per-file basis, and each per-file compression algorithm needs to be marked in the on-disk superblock for initialization. However, syzkaller can generate inconsistent crafted images that use an unsupported algorithm for specific inodes; thus, an unexpected "BUG: kernel NULL pointer dereference" can be raised. Fix this by checking against `sbi->available_compr_algs` for each compressed inode. Incorrect !erofs_sb_has_compr_cfgs preset bitmap is now fixed together since it was harmless previously. Reported-by: Fixes: 14373711dd54 ("erofs: add on-disk compression configurations") Signed-off-by: Gao Xiang --- change since v1: - fix left-shift overflow (undefined behavior). fs/erofs/decompressor.c | 2 +- fs/erofs/zmap.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 021be5feb1bc..af98e88908ee 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -398,7 +398,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) int size, ret = 0; if (!erofs_sb_has_compr_cfgs(sbi)) { - sbi->available_compr_algs = Z_EROFS_COMPRESSION_LZ4; + sbi->available_compr_algs = 1 << Z_EROFS_COMPRESSION_LZ4; return z_erofs_load_lz4_config(sb, dsb, NULL, 0); } diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 7b55111fd533..6f10bc8bbb1c 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -578,6 +578,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) { struct erofs_inode *const vi = EROFS_I(inode); struct super_block *const sb = inode->i_sb; + struct erofs_sb_info *sbi = EROFS_SB(sb); int err, headnr; erofs_off_t pos; struct erofs_buf buf = __EROFS_BUF_INITIALIZER; @@ -624,10 +625,12 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) headnr = 0; if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX || - vi->z_algorithmtype[++headnr] >= Z_EROFS_COMPRESSION_MAX) { - erofs_err(sb, "unknown HEAD%u format %u for nid %llu, please upgrade kernel", + !(sbi->available_compr_algs & (1 << vi->z_algorithmtype[0])) || + vi->z_algorithmtype[++headnr] >= Z_EROFS_COMPRESSION_MAX || + !(sbi->available_compr_algs & (1 << vi->z_algorithmtype[headnr]))) { + erofs_err(sb, "inconsistent HEAD%u algorithm format %u for nid %llu", headnr + 1, vi->z_algorithmtype[headnr], vi->nid); - err = -EOPNOTSUPP; + err = -EFSCORRUPTED; goto out_put_metabuf; } -- 2.39.3