From: Shuah Khan <skhan@linuxfoundation.org>
To: "Everest K.C." <everestkc@everestkc.com.np>
Cc: dpenkler@gmail.com, gregkh@linuxfoundation.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] staging: gpib: Move free after the variable use has been completed
Date: Tue, 15 Oct 2024 16:55:34 -0600 [thread overview]
Message-ID: <f53523ff-1222-4fc0-9069-10ab895e1136@linuxfoundation.org> (raw)
In-Reply-To: <CAEO-vhEwkQKnPprdw_r=mg6KRbadY6B4A3R_sOsyH0ds78wb2g@mail.gmail.com>
On 10/15/24 16:48, Everest K.C. wrote:
> On Tue, Oct 15, 2024 at 4:35 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>>
>> On 10/15/24 15:51, Everest K.C. wrote:
>>> The variable `in_data` is freed, but used later in the code.
>>> Fix it by moving the freeing the memory after it use has been
>>> completed.
>>>
>>> This issue was reported by Coverity Scan.
>>> Report:
>>> CID 1600783: (#1 of 1): Use after free (USE_AFTER_FREE)
>>> 19. pass_freed_arg: Passing freed pointer in_data as an argument to
>>> ni_usb_dump_raw_block.
>>>
>>> Fixes: 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver")
>>> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
>>> ---
>>> drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
>>> index 1da263676f2a..75f39e1f3ed1 100644
>>> --- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
>>> +++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
>>> @@ -690,12 +690,12 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
>>> kfree(in_data);
>>> return parse_retval;
>>> }
>>> - kfree(in_data);
>>> if (actual_length != length - status.count) {
>>> pr_err("%s: actual_length=%i expected=%li\n",
>>> __func__, actual_length, (long)(length - status.count));
>>> ni_usb_dump_raw_block(in_data, usb_bytes_read);
>>> }
>>> + kfree(in_data);
>>> switch (status.error_code) {
>>> case NIUSB_NO_ERROR:
>>> retval = 0;
>>
>> Looks good to me. Isn't this on next though. Don't forget to
>> indicate it is against next.
> No, it was fixed in the linux-staging repo.
>> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
>>
Okay - by the way the same problem is in ni_usb_write_registers().
Did coverity catch that one?
Both problems could be fix in one patch - I will leave it up to the
maintainers to make a call on two patches or a single patch.
thanks,
-- Shuah
next prev parent reply other threads:[~2024-10-15 22:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 21:51 [PATCH] staging: gpib: Move free after the variable use has been completed Everest K.C.
2024-10-15 22:35 ` Shuah Khan
2024-10-15 22:48 ` Everest K.C.
2024-10-15 22:55 ` Shuah Khan [this message]
2024-10-15 23:04 ` Everest K.C.
2024-10-15 23:29 ` Shuah Khan
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=f53523ff-1222-4fc0-9069-10ab895e1136@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=dpenkler@gmail.com \
--cc=everestkc@everestkc.com.np \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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