From patchwork Thu Feb 29 20:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fedor Pchelkin X-Patchwork-Id: 208513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp679386dyb; Thu, 29 Feb 2024 13:04:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUTwivtAh4vCC7UYhVXPgs8tiG7pnfXayaR5d2lYvskIep5PwYmfAeW2BZQS8ECIJ4wvM7zsbPHNB9Cnf/ojTVVtPkhIg== X-Google-Smtp-Source: AGHT+IHALOWyG2FKarfffzt/zGkn8HqbwitCjkgV5+ofdFyjmHBeurQPWjZJeR67ZfMV3lulNMZj X-Received: by 2002:a05:622a:451:b0:42e:8523:6c58 with SMTP id o17-20020a05622a045100b0042e85236c58mr4263661qtx.18.1709240648707; Thu, 29 Feb 2024 13:04:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709240648; cv=pass; d=google.com; s=arc-20160816; b=zM/8FSK91o16sHpVZQpzW1q8TGgCb9rxjSam7aOQ3Zhh0csQoKUXgYb82P7fwE6yp7 pZwFVGZoPeAtD52tKfdhSn/OLlD0AiA7KRFppT7jR9uEASScOJP3P8Bke2DRecvJsU6V CPTtgOsIFk9KKEaRHHYSExLZ1ENEyjqPqCm7DQi1umBSVpq7rjyE/dgHqLxFuFH43oLC xVghmTTO4jjrqHDmNactoAuFDfJdok/RSAaI9TYgJc1oZf3PtPkxzXd4SphOxvccaPln nca8PVxWQxjm1WkYBX2qO7xmwTkbRX0zJqp98xk8D2hUPIA5Bl5uMeUp2mxmzi65UgaL jXkA== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=eANDFJjcF28TbbY3NAVdjRQJ+bbD85155CR8rqMcY8E=; fh=Yy07v4PwG5XCiSrnLNWvf4WC/PqKjiDzd8mPfIrF258=; b=GWJzK5GOGnpYw4mz2Kh1vZofseAHJmCCx0wKZqkPOBZO/jC3VnXUU4Dl415CRBtulj uzLeIlGuVnYscTeSXiZ/0BwtSZE2+yeRA5XPPbnbMOchivJtTRVmDJcEL/WN9aKPbGbo J6Co4QnfCzxXPM//NzdFuKfX/tYhc2c0Jtglnmu1mxzT+YLmMzTcrpKN4OBLotDGsjtD IolgdwJykSQ+cjmRW/hllLN/3HSUbJgZGFVzb6aj2+e/mO1r7ZyjNBK1N3Tst0EKIJqU RhrSV5wGjsl9+TWnyTM1RwpTUyioi9A7hNuBE19NH0y0e2k5602I0YCNynRVuqYFAhuh A4cA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=SfBEQkle; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-87526-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87526-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b17-20020ac86791000000b0042eaf9b3a7csi2041903qtp.660.2024.02.29.13.04.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 13:04:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87526-ouuuleilei=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; dkim=pass header.i=@ispras.ru header.s=default header.b=SfBEQkle; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-87526-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87526-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru 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 773321C22940 for ; Thu, 29 Feb 2024 21:04:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C3EA153BF6; Thu, 29 Feb 2024 20:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="SfBEQkle" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6F7914405D; Thu, 29 Feb 2024 20:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709239383; cv=none; b=tUk5LwHHlPngCfjMqqjpvzPN6vd4mEABquqAS8JnStkJepF3rMY5uKHxNgKrqxfMDSt32QYhvr5QLe7QBt4qBoHY29i8SPbVkc9jmEY0mjiFXD/qwNDpupZhbu/ugnqrRwF1VB43k9I09EQUz1c0tfaw1uOXxh3i9cqQU+0aVSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709239383; c=relaxed/simple; bh=KXdgm/I/ewft6TDONs1/C8PbLQ8HZujA3uwky710JcQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bc+hElg0ImP5fyCqGEj5EDL9MDjPRqMa5IGKW3XW6z71U9hsjT9VZcPQ1R9fjXeQ78Ha2pGlxHrAr67sUFrAgst3BLA4J48WZZzn/wqJc1c8c4q49v5/zUmbkWxOyrMe8uK/gOnwj2+jBdsm1kXHgO6vyxIW/VUP0aYTkjf5Dck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=SfBEQkle; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from localhost.ispras.ru (unknown [10.10.165.8]) by mail.ispras.ru (Postfix) with ESMTPSA id 3295940B27A1; Thu, 29 Feb 2024 20:42:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 3295940B27A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1709239372; bh=eANDFJjcF28TbbY3NAVdjRQJ+bbD85155CR8rqMcY8E=; h=From:To:Cc:Subject:Date:From; b=SfBEQkleMTQQB8i9ri0DjO6Qh0zDw1x5+QA69r+8BbMw93Gf8bbETFYaG4995ugcW lxfXENFRm1JGJ1peL2XYto6WOYj07fixAqX41BTfoWTSAD/03u4eLrGLcwVomxKABH sU264do6bHhtUbcKqgQjdJfblDDtLGX38dd5fH6E= From: Fedor Pchelkin To: Richard Weinberger Cc: Fedor Pchelkin , Miquel Raynal , Vignesh Raghavendra , Artem Bityutskiy , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org, stable@vger.kernel.org Subject: [PATCH] ubi: eba: properly rollback inside self_check_eba Date: Thu, 29 Feb 2024 23:42:36 +0300 Message-ID: <20240229204237.30453-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792268722061341252 X-GMAIL-MSGID: 1792268722061341252 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 Reviewed-by: Zhihao Cheng --- drivers/mtd/ubi/eba.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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;