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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19F06C433EF for ; Mon, 15 Nov 2021 01:19:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA05660F0F for ; Mon, 15 Nov 2021 01:19:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236222AbhKOBWt (ORCPT ); Sun, 14 Nov 2021 20:22:49 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:15822 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbhKOBWZ (ORCPT ); Sun, 14 Nov 2021 20:22:25 -0500 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Hsrv10lWJz9129; Mon, 15 Nov 2021 09:19:09 +0800 (CST) Received: from dggpeml500020.china.huawei.com (7.185.36.88) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 15 Nov 2021 09:19:23 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500020.china.huawei.com (7.185.36.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Mon, 15 Nov 2021 09:19:23 +0800 From: Baokun Li To: , , CC: , , Hulk Robot Subject: [PATCH -next 2/3] ubifs: fix double return leb in ubifs_garbage_collect Date: Mon, 15 Nov 2021 09:31:43 +0800 Message-ID: <20211115013144.2479319-3-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211115013144.2479319-1-libaokun1@huawei.com> References: <20211115013144.2479319-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500020.china.huawei.com (7.185.36.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If ubifs_garbage_collect_leb() returns -EAGAIN and enters the "out" branch, ubifs_return_leb will execute twice on the same lnum. This can cause data loss in concurrency situations. Reported-by: Hulk Robot Signed-off-by: Baokun Li --- fs/ubifs/gc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 05e1eeae8457..1f74a127fe3a 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c @@ -758,6 +758,8 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway) err = ubifs_return_leb(c, lp.lnum); if (err) ret = err; + /* Maybe double return LEB if goto out */ + lp.lnum = -1; break; } goto out; -- 2.31.1