Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5266332rwb; Sun, 4 Dec 2022 18:03:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5OHqhsSZgzAgeWj7zgM6/iEOFtFdribUWK5eT3CXCyNcqe+zVfYCyKy2MN3MNu9z6uroRT X-Received: by 2002:a17:90a:ea8b:b0:219:b015:58cd with SMTP id h11-20020a17090aea8b00b00219b01558cdmr8151309pjz.40.1670205805684; Sun, 04 Dec 2022 18:03:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670205805; cv=none; d=google.com; s=arc-20160816; b=TRicQ32ZM/3q0pJGgmmMccYb2dC+eWMT5oI+zRr2f0buyaRM2tj+oiTH13v3cigyO+ gG12o8AP9TLZPSI7hDsbwvLDnib84frdaV2ZO9E/u5WWsUoEBQcAHGnDOVIjqFUVdVKa teS/oVFkYIvb2oe9g8cV8sWHY4n3cM2kawkisePUfAfH6RBPq+mMD3B+UwXT+uDAD44u zk1ptF9MCgpiy7KmKQy03PB6e8Iz3t01DdUs/h2hs6iXsXmc3FdTbYROAv7wfBEI4w1O vhCrTEjVlRCFy3MPPItoRNSVSb7ZFrPxIwifSQPXIyPl/dh992L+JpSWOBCAnawB+JzN H30Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=6yht2HyKo0kjat2a3IvSRvhvr6eJDLBGyD6nqjPyJ9E=; b=bZUJnzTWz4cjro4LkV9+VrZ0Of6gtjsdB74/9Hud7sflObjd9XMgY6uUL7sGlH6Mha LqD2488qvBNsnJ5QSfMmHhk0Vc4jYpDrprVMsvSXTIT9vCOeicyXcYA9Ajn9eEHoBKsp hzyYM+F+0GQc1td/nHXFqC0jflLHY/baTZN5bY2K6Pb/J8SIWu6ane8LKuPnPpjcp4PV EsdBBj2hQJ4RfRQofVnMl3uKeg9G8xRZlTaOuuLmvNE+96gtUNTyfFBke6ghImdRxjZU 5izBZwEbFPzunWgsqXNSzubPeTOZD9M8zEsGFQ+QbLxizy+UjqohJvuXQx8MBvmpbZsc R/6g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k4-20020a170902c40400b00188a915034bsi16019727plk.340.2022.12.04.18.03.14; Sun, 04 Dec 2022 18:03:25 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbiLEBx0 (ORCPT + 82 others); Sun, 4 Dec 2022 20:53:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231138AbiLEBxZ (ORCPT ); Sun, 4 Dec 2022 20:53:25 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F216B4AE for ; Sun, 4 Dec 2022 17:53:23 -0800 (PST) Received: from dggpemm500013.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NQRPv04J5zFqnN; Mon, 5 Dec 2022 09:52:35 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 5 Dec 2022 09:53:21 +0800 From: Chen Zhongjin To: , , CC: , , , , Subject: [PATCH v2] erofs: Fix pcluster memleak when m_pa is zero Date: Mon, 5 Dec 2022 09:50:24 +0800 Message-ID: <20221205015024.66868-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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 syzkaller reported a memleak: https://syzkaller.appspot.com/bug?id=62f37ff612f0021641eda5b17f056f1668aa9aed unreferenced object 0xffff88811009c7f8 (size 136): ... backtrace: [] z_erofs_do_read_page+0x99b/0x1740 [] z_erofs_readahead+0x24e/0x580 [] read_pages+0x86/0x3d0 ... syzkaller constructed a case: in z_erofs_register_pcluster(), ztailpacking = false and map->m_pa = zero. This makes pcl->obj.index be zero although pcl is not a inline pcluster. Then following path adds refcount for grp, but the refcount won't be put because pcl is inline. z_erofs_readahead() z_erofs_do_read_page() # for another page z_erofs_collector_begin() erofs_find_workgroup() erofs_workgroup_get() Since it's illegal for map->m_pa to be zero, add check here to avoid registering the pcluster which would be leaked. Fixes: cecf864d3d76 ("erofs: support inline data decompression") Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com Signed-off-by: Chen Zhongjin --- As Gao's advice, we should fail to register pcluster if m_pa is zero. Maked it this way and changed the commit message. --- fs/erofs/zdata.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index b792d424d774..7826634f4f51 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -488,7 +488,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe) struct erofs_workgroup *grp; int err; - if (!(map->m_flags & EROFS_MAP_ENCODED)) { + if (!(map->m_flags & EROFS_MAP_ENCODED) || + !(map->m_pa >> PAGE_SHIFT)) { DBG_BUGON(1); return -EFSCORRUPTED; } -- 2.17.1