From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 55DC9328638; Mon, 27 Oct 2025 18:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591312; cv=none; b=UqyydNNED8uQSSAv1kajIx9H1Ad+gADGFv7rL3nGusqKZ5r9vO3kyIEkf9jtKUT70TPRJj4ajD3sevKAvI3ur+zr4OyQBuSEITPhT7Gez46Unlv8bvxSh2XAlX6pRxKrU+d+hWXhWpxRqfVkZKbcqeaAQSmCzzPuLAGeGKcaTws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591312; c=relaxed/simple; bh=ThIpqebrVOP3kae7cR2YhUpJlav684i1urwi2xtNG3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyE0eek1/439SzFcsMQUBQtgdC5srlUW/sZaruVmzKD3VTGVCIh5tocKuQYQ/VLSiLpIICkgcIgf4uv+eHnDTJUdl7+L+nbAmBJ4XZd6Bnf+YpmOa0xtiekp4Qrs+ekxJichAG3bdBQXJwIJ3qHHmSnFiLFo+kTsI3RYChK3Juc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V4vDYLa+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="V4vDYLa+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE21AC4CEF1; Mon, 27 Oct 2025 18:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591312; bh=ThIpqebrVOP3kae7cR2YhUpJlav684i1urwi2xtNG3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4vDYLa+gc6xBHqFk6ez8ix15RW8PSCtooEL/eioX/fAumLwG4F/MbZSyMBfgDp1X WmJNcOyYhHoE+MCzkK/iYrktZLO9xZG5EjMlrmQOuwEAM2cO+wpemhiA6smCx1Frfi ViDQHem1CLGjSgjC6IAuZdp4xtuaxLqhEesC5UQg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thorsten Blum , Don Brace , "Martin K. Petersen" Subject: [PATCH 5.10 147/332] scsi: hpsa: Fix potential memory leak in hpsa_big_passthru_ioctl() Date: Mon, 27 Oct 2025 19:33:20 +0100 Message-ID: <20251027183528.516123866@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thorsten Blum commit b81296591c567b12d3873b05a37b975707959b94 upstream. Replace kmalloc() followed by copy_from_user() with memdup_user() to fix a memory leak that occurs when copy_from_user(buff[sg_used],,) fails and the 'cleanup1:' path does not free the memory for 'buff[sg_used]'. Using memdup_user() avoids this by freeing the memory internally. Since memdup_user() already allocates memory, use kzalloc() in the else branch instead of manually zeroing 'buff[sg_used]' using memset(0). Cc: stable@vger.kernel.org Fixes: edd163687ea5 ("[SCSI] hpsa: add driver for HP Smart Array controllers.") Signed-off-by: Thorsten Blum Acked-by: Don Brace Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/hpsa.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -6500,18 +6500,21 @@ static int hpsa_big_passthru_ioctl(struc while (left) { sz = (left > ioc->malloc_size) ? ioc->malloc_size : left; buff_size[sg_used] = sz; - buff[sg_used] = kmalloc(sz, GFP_KERNEL); - if (buff[sg_used] == NULL) { - status = -ENOMEM; - goto cleanup1; - } + if (ioc->Request.Type.Direction & XFER_WRITE) { - if (copy_from_user(buff[sg_used], data_ptr, sz)) { - status = -EFAULT; + buff[sg_used] = memdup_user(data_ptr, sz); + if (IS_ERR(buff[sg_used])) { + status = PTR_ERR(buff[sg_used]); + goto cleanup1; + } + } else { + buff[sg_used] = kzalloc(sz, GFP_KERNEL); + if (!buff[sg_used]) { + status = -ENOMEM; goto cleanup1; } - } else - memset(buff[sg_used], 0, sz); + } + left -= sz; data_ptr += sz; sg_used++;