From: Bodo Stroesser <bostroesser@gmail.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] scsi: target: tcmu: Use struct_size() helper in kmalloc()
Date: Wed, 29 Sep 2021 19:35:07 +0200 [thread overview]
Message-ID: <289a7052-7062-ce88-7cbd-dd29f23b4c60@gmail.com> (raw)
In-Reply-To: <20210927224344.GA190701@embeddedor>
On 28.09.21 00:43, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows
> that, in the worst scenario, could lead to heap overflows.
>
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/target/target_core_user.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index 9f552f48084c..dc220fad06fa 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -1255,7 +1255,6 @@ tcmu_tmr_notify(struct se_device *se_dev, enum tcm_tmreq_table tmf,
> {
> int i = 0, cmd_cnt = 0;
> bool unqueued = false;
> - uint16_t *cmd_ids = NULL;
> struct tcmu_cmd *cmd;
> struct se_cmd *se_cmd;
> struct tcmu_tmr *tmr;
> @@ -1292,7 +1291,7 @@ tcmu_tmr_notify(struct se_device *se_dev, enum tcm_tmreq_table tmf,
> pr_debug("TMR event %d on dev %s, aborted cmds %d, afflicted cmd_ids %d\n",
> tcmu_tmr_type(tmf), udev->name, i, cmd_cnt);
>
> - tmr = kmalloc(sizeof(*tmr) + cmd_cnt * sizeof(*cmd_ids), GFP_NOIO);
> + tmr = kmalloc(struct_size(tmr, tmr_cmd_ids, cmd_cnt), GFP_NOIO);
> if (!tmr)
> goto unlock;
>
>
Looks good. Thank you.
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>
next prev parent reply other threads:[~2021-09-29 17:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 22:43 Gustavo A. R. Silva
2021-09-29 17:35 ` Bodo Stroesser [this message]
2021-10-12 20:35 ` Martin K. Petersen
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=289a7052-7062-ce88-7cbd-dd29f23b4c60@gmail.com \
--to=bostroesser@gmail.com \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=target-devel@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
all inboxes | Powered by JetHome®