Linux-Raid Archives mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: yukuai3@huawei.com
Cc: linux-raid@vger.kernel.org
Subject: [bug report] md: also clone new io if io accounting is disabled
Date: Wed, 31 Jan 2024 14:17:00 +0300	[thread overview]
Message-ID: <2cf10b2e-3703-414b-99b6-457dd4b14177@moroto.mountain> (raw)

Hello Yu Kuai,

The patch c687297b8845: "md: also clone new io if io accounting is
disabled" from Jun 22, 2023 (linux-next), leads to the following
Smatch static checker warning:

	drivers/md/md.c:8718 md_clone_bio()
	potential NULL container_of 'clone'

drivers/md/md.c
    8711 static void md_clone_bio(struct mddev *mddev, struct bio **bio)
    8712 {
    8713         struct block_device *bdev = (*bio)->bi_bdev;
    8714         struct md_io_clone *md_io_clone;
    8715         struct bio *clone =
    8716                 bio_alloc_clone(bdev, *bio, GFP_NOIO, &mddev->io_clone_set);

Generally in the kernel, you have to check for allocation failure.  In
this case if the allocation fails it leads to a NULL dereference.

    8717 
--> 8718         md_io_clone = container_of(clone, struct md_io_clone, bio_clone);
    8719         md_io_clone->orig_bio = *bio;
    8720         md_io_clone->mddev = mddev;
    8721         if (blk_queue_io_stat(bdev->bd_disk->queue))
    8722                 md_io_clone->start_time = bio_start_io_acct(*bio);
    8723 
    8724         clone->bi_end_io = md_end_clone_io;
    8725         clone->bi_private = md_io_clone;
    8726         *bio = clone;
    8727 }

regards,
dan carpenter

             reply	other threads:[~2024-01-31 11:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 11:17 Dan Carpenter [this message]
2024-02-01  1:35 ` [bug report] md: also clone new io if io accounting is disabled Yu Kuai

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=2cf10b2e-3703-414b-99b6-457dd4b14177@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=yukuai3@huawei.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).