mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: John Garry <john.g.garry@oracle.com>, hch@infradead.org
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: Explanation on Uninitialized Variable bio in blk_rq_prep_clone
Date: Sun, 6 Oct 2024 12:28:56 +0530	[thread overview]
Message-ID: <b22f1750-c53d-481f-8233-12adac30a807@gmail.com> (raw)
In-Reply-To: <6a0ec577-fba1-44b3-87d8-3a202df19d8c@oracle.com>

On 04/10/24 20:03, John Garry wrote:
> On 04/10/2024 15:10, SurajSonawane2415 wrote:
>> Explaination of how bio could be used uninitialized in this function:
>>
>> In the function blk_rq_prep_clone, the variable bio is declared but 
>> can remain uninitialized
>> if the allocation with bio_alloc_clone fails. This can lead to 
>> undefined behavior when the
>> function attempts to free bio in the error handling section using 
>> bio_put(bio).
>> By initializing bio to NULL at declaration, we ensure that the cleanup 
>> code will only
>> interact with bio if it has been successfully allocated.
>>
>>
> 
> What about if rq_src->bio is NULL for blk_rq_prep_clone() -> 
> __rq_for_each_bio(,rq_src):
> 
> #define __rq_for_each_bio(_bio, rq)    \
>      if ((rq->bio))            \
>          for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
> 
> Then I don't think bio it get init'ed. Whether this is possible 
> (rq_src->bio is NULL) is another question.

Hi Keith,

You're right to bring this up. If rq_src->bio is NULL, the 
__rq_for_each_bio macro will skip the loop, meaning the bio variable 
won't be used at all. So, even if bio isn’t initialized, it won't cause 
any issues in that case.

Thanks for pointing that out.

Best regards,
Suraj

  parent reply	other threads:[~2024-10-06  6:59 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-04 10:08 [PATCH] block: Fix uninitialized symbol 'bio' " SurajSonawane2415
2024-10-04 12:22 ` Christoph Hellwig
2024-10-04 14:10   ` Explanation on Uninitialized Variable bio " SurajSonawane2415
2024-10-04 14:15     ` Hannes Reinecke
2024-10-04 14:33     ` John Garry
2024-10-04 14:40       ` Keith Busch
2024-10-06  6:58       ` Suraj Sonawane [this message]
2024-10-06  7:11         ` Suraj Sonawane
2024-10-04 14:39     ` Keith Busch
2024-10-06  7:03       ` Suraj Sonawane
2024-10-07  5:50         ` Christoph Hellwig
2024-10-07 19:58 ` [PATCH v2] block: Fix uninitialized symbol 'bio' " SurajSonawane2415
2024-10-08  4:23   ` Christoph Hellwig
2024-10-08 12:04 ` [PATCH v3] " SurajSonawane2415
2024-10-08 12:06   ` Christoph Hellwig
2024-10-08 14:52   ` Keith Busch
2024-10-08 15:35     ` Keith Busch
2024-10-08 17:52 ` [PATCH v4] " SurajSonawane2415
2024-10-09  7:30   ` Christoph Hellwig
2024-10-09 11:00     ` Suraj Sonawane
2024-10-09 11:37       ` Christoph Hellwig
2024-10-09 11:40         ` Suraj Sonawane
2024-11-15 16:07   ` Suraj Sonawane
2024-11-15 16:10     ` Jens Axboe
2024-11-16 11:32       ` Suraj Sonawane
2024-11-18  6:28         ` Christoph Hellwig
2024-11-19 16:53           ` Suraj Sonawane

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=b22f1750-c53d-481f-8233-12adac30a807@gmail.com \
    --to=surajsonawane0215@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=john.g.garry@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@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®