linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jay Fang <f.fangjian@huawei.com>, Mark Brown <broonie@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-spi@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 02/20] spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages()
Date: Sun,  4 Jul 2021 19:11:37 -0400	[thread overview]
Message-ID: <20210704231155.1491795-2-sashal@kernel.org> (raw)
In-Reply-To: <20210704231155.1491795-1-sashal@kernel.org>

From: Jay Fang <f.fangjian@huawei.com>

[ Upstream commit 026a1dc1af52742c5897e64a3431445371a71871 ]

pch_spi_set_tx() frees data->pkt_tx_buff on failure of kzalloc() for
data->pkt_rx_buff, but its caller, pch_spi_process_messages(), will
free data->pkt_tx_buff again. Set data->pkt_tx_buff to NULL after
kfree() to avoid double free.

Signed-off-by: Jay Fang <f.fangjian@huawei.com>
Link: https://lore.kernel.org/r/1620284888-65215-1-git-send-email-f.fangjian@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/spi/spi-topcliff-pch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index fe707440f8c3..9b24ebbba346 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -585,8 +585,10 @@ static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw)
 	data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);
 	if (data->pkt_tx_buff != NULL) {
 		data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);
-		if (!data->pkt_rx_buff)
+		if (!data->pkt_rx_buff) {
 			kfree(data->pkt_tx_buff);
+			data->pkt_tx_buff = NULL;
+		}
 	}
 
 	if (!data->pkt_rx_buff) {
-- 
2.30.2


  reply	other threads:[~2021-07-04 23:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-04 23:11 [PATCH AUTOSEL 4.9 01/20] spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' Sasha Levin
2021-07-04 23:11 ` Sasha Levin [this message]
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 03/20] spi: omap-100k: Fix the length judgment problem Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 04/20] crypto: nx - add missing MODULE_DEVICE_TABLE Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 05/20] media: cpia2: fix memory leak in cpia2_usb_probe Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 06/20] media: cobalt: fix race condition in setting HPD Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 07/20] media: pvrusb2: fix warning in pvr2_i2c_core_done Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 08/20] crypto: qat - check return code of qat_hal_rd_rel_reg() Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 09/20] crypto: qat - remove unused macro in FW loader Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 10/20] media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 11/20] media: bt8xx: Fix a missing check bug in bt878_probe Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 12/20] media: st-hva: Fix potential NULL pointer dereferences Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 13/20] mmc: via-sdmmc: add a check against NULL pointer dereference Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 14/20] crypto: shash - avoid comparing pointers to exported functions under CFI Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 15/20] media: dvb_net: avoid speculation from net slot Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 16/20] media: siano: fix device register error path Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 17/20] btrfs: abort transaction if we fail to update the delayed inode Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 18/20] btrfs: make Private2 lifespan more consistent Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 19/20] btrfs: disable build on platforms having page size 256K Sasha Levin
2021-07-04 23:11 ` [PATCH AUTOSEL 4.9 20/20] regulator: da9052: Ensure enough delay time for .set_voltage_time_sel Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210704231155.1491795-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=broonie@kernel.org \
    --cc=f.fangjian@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).