From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Ally Heev <allyheev@gmail.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH] scsi: fix uninitialized pointers with free attr
Date: Wed, 05 Nov 2025 09:21:45 -0500 [thread overview]
Message-ID: <6d199d062b16abfbf083750820d7a39cb2ebf144.camel@HansenPartnership.com> (raw)
In-Reply-To: <20251105-aheev-uninitialized-free-attr-scsi-v1-1-d28435a0a7ea@gmail.com>
On Wed, 2025-11-05 at 19:44 +0530, Ally Heev wrote:
> Uninitialized pointers with `__free` attribute can cause undefined
> behaviour as the memory assigned(randomly) to the pointer is freed
> automatically when the pointer goes out of scope
>
> scsi doesn't have any bugs related to this as of now, but
> it is better to initialize and assign pointers with `__free` attr
> in one statement to ensure proper scope-based cleanup
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes:
> https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/
> Signed-off-by: Ally Heev <allyheev@gmail.com>
> ---
> drivers/scsi/scsi_debug.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index
> b2ab97be5db3d43d5a5647968623b8db72448379..89b36d65926bdd15c0ae93a6bd2
> ea968e25c0e74 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -2961,11 +2961,11 @@ static int resp_mode_sense(struct scsi_cmnd
> *scp,
> int target_dev_id;
> int target = scp->device->id;
> unsigned char *ap;
> - unsigned char *arr __free(kfree);
> unsigned char *cmd = scp->cmnd;
> bool dbd, llbaa, msense_6, is_disk, is_zbc, is_tape;
>
> - arr = kzalloc(SDEBUG_MAX_MSENSE_SZ, GFP_ATOMIC);
> + unsigned char *arr __free(kfree) =
> kzalloc(SDEBUG_MAX_MSENSE_SZ, GFP_ATOMIC);
> +
Moving variable assignments inside code makes it way harder to read.
Given that compilers will eventually detect if we do a return before
initialization, can't you have smatch do the same rather than trying to
force something like this?
Regards,
James
next prev parent reply other threads:[~2025-11-05 14:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 14:14 [PATCH] scsi: fix uninitialized pointers with free attr Ally Heev
2025-11-05 14:21 ` James Bottomley [this message]
2025-11-05 14:46 ` Dan Carpenter
2025-11-05 15:32 ` James Bottomley
2025-11-06 14:46 ` Dan Carpenter
2025-11-06 16:06 ` James Bottomley
2025-11-18 6:17 ` Dan Carpenter
2025-11-18 13:21 ` James Bottomley
2025-11-18 14:22 ` Dan Carpenter
2025-11-19 6:56 ` ally heev
2025-11-19 8:31 ` Christoph Hellwig
2025-11-19 12:43 ` James Bottomley
2025-11-20 4:15 ` 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=6d199d062b16abfbf083750820d7a39cb2ebf144.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=allyheev@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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