mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Riyan Dhiman <riyandhiman14@gmail.com>
To: bvanassche@acm.org, aacraid@microsemi.com,
	James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: aacraid: Fix memory leak in open_getadapter_fib function
Date: Wed,  4 Sep 2024 10:28:18 +0530	[thread overview]
Message-ID: <20240904045820.5510-1-riyandhiman14@gmail.com> (raw)
In-Reply-To: <bf6746d0-d8cc-412e-ac7b-6f17c3e3de9d@acm.org>

>>> Just above the copy_to_user() call there is the following statement:
>>>
>>> 	list_add_tail(&fibctx->next, &dev->fib_list);
>>>
>>> Does that mean that the above kfree() will cause list corruption?
>> 
>> Yes, you are correct. I overlooked that fibctx is part of a list, and freeing the
>> memory without removing the list entry would corrupt the list.
>> The list entry should be deleted before freeing the memory if copy_to_user() fails.
>
> Are you sure that this is what the code should do?

If copy_to_user function fails that means data was not copied to args successfully, which can leads to 
issue as args might remain unchanged or in an uninteded state. Since we are returning an -EFAULT error, 
we should free fibctx and remove the list entry in the case of an error. If there are any other methods, 
additional checks, or potential issues with this approach that I should consider, 
please let me know, and I'll make the necessary adjustments promptly.

Regards,
Riyan Dhiman

  parent reply	other threads:[~2024-09-04  4:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03 18:54 Riyan Dhiman
2024-09-03 19:18 ` Bart Van Assche
2024-09-03 20:30   ` Riyan Dhiman
2024-09-03 21:01     ` Bart Van Assche
2024-09-04  4:43       ` Riyan Dhiman
2024-09-04  4:58       ` Riyan Dhiman [this message]
2024-09-04 17:23         ` Bart Van Assche

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=20240904045820.5510-1-riyandhiman14@gmail.com \
    --to=riyandhiman14@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=aacraid@microsemi.com \
    --cc=bvanassche@acm.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

all inboxes | Powered by JetHome®