* [PATCH][next] scsi: sg: Fix use of pointer sfp after it has been kfree'd
@ 2021-03-11 10:37 Colin King
2021-03-11 17:17 ` Douglas Gilbert
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-03-11 10:37 UTC (permalink / raw)
To: Doug Gilbert, James E . J . Bottomley, Martin K . Petersen,
Hannes Reinecke, linux-scsi
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently SG_LOG is referencing sfp after it has been kfree'd which
is probably a bad thing to do. Fix this by kfree'ing sfp after
SG_LOG.
Addresses-Coverity: ("Use after free")
Fixes: af1fc95db445 ("scsi: sg: Replace rq array with xarray")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/scsi/sg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2d4bbc1a1727..79f05afa4407 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -3799,10 +3799,10 @@ sg_add_sfp(struct sg_device *sdp)
if (rbuf_len > 0) {
srp = sg_build_reserve(sfp, rbuf_len);
if (IS_ERR(srp)) {
- kfree(sfp);
err = PTR_ERR(srp);
SG_LOG(1, sfp, "%s: build reserve err=%ld\n", __func__,
-err);
+ kfree(sfp);
return ERR_PTR(err);
}
if (srp->sgat_h.buflen < rbuf_len) {
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] scsi: sg: Fix use of pointer sfp after it has been kfree'd
2021-03-11 10:37 [PATCH][next] scsi: sg: Fix use of pointer sfp after it has been kfree'd Colin King
@ 2021-03-11 17:17 ` Douglas Gilbert
0 siblings, 0 replies; 2+ messages in thread
From: Douglas Gilbert @ 2021-03-11 17:17 UTC (permalink / raw)
To: Colin King, James E . J . Bottomley, Martin K . Petersen,
Hannes Reinecke, linux-scsi
Cc: kernel-janitors, linux-kernel
On 2021-03-11 5:37 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently SG_LOG is referencing sfp after it has been kfree'd which
> is probably a bad thing to do. Fix this by kfree'ing sfp after
> SG_LOG.
>
> Addresses-Coverity: ("Use after free")
> Fixes: af1fc95db445 ("scsi: sg: Replace rq array with xarray")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Thanks.
> ---
> drivers/scsi/sg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 2d4bbc1a1727..79f05afa4407 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -3799,10 +3799,10 @@ sg_add_sfp(struct sg_device *sdp)
> if (rbuf_len > 0) {
> srp = sg_build_reserve(sfp, rbuf_len);
> if (IS_ERR(srp)) {
> - kfree(sfp);
> err = PTR_ERR(srp);
> SG_LOG(1, sfp, "%s: build reserve err=%ld\n", __func__,
> -err);
> + kfree(sfp);
> return ERR_PTR(err);
> }
> if (srp->sgat_h.buflen < rbuf_len) {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-11 17:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 10:37 [PATCH][next] scsi: sg: Fix use of pointer sfp after it has been kfree'd Colin King
2021-03-11 17:17 ` Douglas Gilbert
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.