Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp3559lqg; Thu, 29 Feb 2024 17:24:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWFZbLkpYvWhadMJUpgGrG1S5jcGAFg3O4DPPgEzX0Q2vNw8dQa7xumjcBWK+HRxPF5IWZ82X4BEshml0lEg88iyxxg9c7dbbu/I2Mmww== X-Google-Smtp-Source: AGHT+IGFINGC4tm4mDoXlJtQkH4L6F5+LDRhacMOzVlhsG9X2heFVgNOvKf3/l1QambtNcTSKdJd X-Received: by 2002:a17:90b:3ccf:b0:299:3ebf:d180 with SMTP id qd15-20020a17090b3ccf00b002993ebfd180mr340008pjb.6.1709256253160; Thu, 29 Feb 2024 17:24:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709256253; cv=pass; d=google.com; s=arc-20160816; b=ntMP0xNeJdbTzF240WzZWs9Bmya1gBSzcq2s6LLHHY5X9pyZCfz0YffYt/FeCeGJFL zE5Ndl7w4C0Pglws4N5g/OMxZAn8CHE1CvWG9i5NFAeMEojNoE9DFJmzkFGndllPV/oT b3rPlPwaicwg3Obdy0gEhfqKFTqyKqr6br87dhEZGKq7cfZn5mt4GWW9RYOdA7VmduJ4 b2fiGjR5xU4Xoup4smjRP1T3IPAN4VLIHn5bra8P+kMJ/kanafFAx8QF+jbmhbvaoMHQ TfeYzbL9XVromU56yRIYBaEpjkIsJJnurl4APzsZfX+LlRhAHPtRMX0SytgI9HuYaIBj bDSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=ldHTSvQMNGK/qBsydwvnjxec2Kslkr9CnXDn97EczQ0=; fh=hJ2QapS2de6GHTBie3V4bhO1zz7ny9vK3acik5AGd8M=; b=MmdyIBF07luO8X3Dxh3Ly/cHs1B7O0tbf6cqlzwezYaV40B7rR/sOUnqBlt1J2o8qw 3XO9k6EFaqET8EJ/mSnx3LRUJ1D4eB0/SwPc2Otq7qB2g/7OLx6ScVFXJ3L00Xr5OFes yqd8xiRAsTCm2HMpDKf4g9WxEWKRam4Kj389rUksdMItkq1Km0JtP6gfbRepwTu7ax6p lNdHl0mUL3kaYu86hyxYiW8PfnLF8aKV7D8tNiboBCXZj2uQcMagRT3GivfCUEhL73fO X/z6c6HFHdujsXhsVGsWXfh+a2OfvK/WiqSrmDl4TMpdG9Vm1ppogi2z2Jo0Iku1Hatj T9nQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87768-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id sn14-20020a17090b2e8e00b0029a5678e1e0si2693240pjb.6.2024.02.29.17.24.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 17:24:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87768-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87768-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D3F4C28521F for ; Fri, 1 Mar 2024 01:24:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F40A2BAF0; Fri, 1 Mar 2024 01:24:07 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 41F5F2B9B9; Fri, 1 Mar 2024 01:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709256246; cv=none; b=cJfSjWAM+3nNu0tuVFikj6GJFQU5OTOy12BZT49h6rcomP42dxUJJmQaWnPdF2+o7tcgmauluE6h6MpH34upaLD7Tz/3i62sizzHruvhXB5zRPicuegJucu1z0l07RIw8OZ+zXKO9vZobIBX1PPq2PhrKQkbou5yhnvSH6ltwds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709256246; c=relaxed/simple; bh=XBpVTizpGtxnNmFfrxzIv8+FmfNwz48diAaegGnbCBY=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=jkqfTD4VzbxhKVI26luiq3g52pPetKJE5Aenn6ihVZ+shHtmvONsV07B/lkXmQchnJQlv5HoHglJbWgyDC/vvTGM3y2k4QkLwOHoxaNuL6CKT8HSoytyIZWsOcUjJooDMnR80sLEEZzz3vKHVsxeOaKoQ/MsPIbTfGLIqKlMVvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Tm9Km5P9GzvW3L; Fri, 1 Mar 2024 09:21:48 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 6D65F14037F; Fri, 1 Mar 2024 09:24:00 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 1 Mar 2024 09:23:58 +0800 Subject: Re: [PATCH] ubi: eba: properly rollback inside self_check_eba To: Fedor Pchelkin , Richard Weinberger CC: Miquel Raynal , Vignesh Raghavendra , Artem Bityutskiy , , , Alexey Khoroshilov , , References: <20240229204237.30453-1-pchelkin@ispras.ru> From: Zhihao Cheng Message-ID: <1421503e-b1d2-87f2-e33e-1a0428100be2@huawei.com> Date: Fri, 1 Mar 2024 09:23:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240229204237.30453-1-pchelkin@ispras.ru> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600013.china.huawei.com (7.193.23.68) ?? 2024/3/1 4:42, Fedor Pchelkin ะด??: > In case of a memory allocation failure in the volumes loop we can only > process the already allocated scan_eba and fm_eba array elements on the > error path - others are still uninitialized. > > Found by Linux Verification Center (linuxtesting.org). > > Fixes: 00abf3041590 ("UBI: Add self_check_eba()") > Cc: stable@vger.kernel.org > Signed-off-by: Fedor Pchelkin > --- > drivers/mtd/ubi/eba.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Reviewed-by: Zhihao Cheng > > diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c > index 8d1f0e05892c..6f5eadb1598d 100644 > --- a/drivers/mtd/ubi/eba.c > +++ b/drivers/mtd/ubi/eba.c > @@ -1557,6 +1557,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap, > GFP_KERNEL); > if (!fm_eba[i]) { > ret = -ENOMEM; > + kfree(scan_eba[i]); > goto out_free; > } > > @@ -1592,7 +1593,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap, > } > > out_free: > - for (i = 0; i < num_volumes; i++) { > + while (--i >= 0) { > if (!ubi->volumes[i]) > continue; > >