From: Dan Carpenter <dan.carpenter@oracle.com>
To: shli@fb.com
Cc: linux-block@vger.kernel.org
Subject: [bug report] nullb: add interface to power on disk
Date: Mon, 28 Aug 2017 21:49:02 +0300 [thread overview]
Message-ID: <20170828184901.ehaflki7emvhrb6a@mwanda> (raw)
Hello Shaohua Li,
The patch cedcafad8277: "nullb: add interface to power on disk" from
Aug 14, 2017, leads to the following static checker warning:
drivers/block/null_blk.c:372 nullb_device_power_store()
warn: 'dev' was already freed.
drivers/block/null_blk.c:1993 null_init()
error: double free of 'dev'
drivers/block/null_blk.c
356
357 static ssize_t nullb_device_power_store(struct config_item *item,
358 const char *page, size_t count)
359 {
360 struct nullb_device *dev = to_nullb_device(item);
361 bool newp = false;
362 ssize_t ret;
363
364 ret = nullb_device_bool_attr_store(&newp, page, count);
365 if (ret < 0)
366 return ret;
367
368 if (!dev->power && newp) {
369 if (test_and_set_bit(NULLB_DEV_FL_UP, &dev->flags))
370 return count;
371 if (null_add_dev(dev)) {
^^^^^^^^^^^^^^^^^
null_add_dev() frees dev on failure
372 clear_bit(NULLB_DEV_FL_UP, &dev->flags);
^^^^^^^^^^
so this is a use after free. The other time null_add_dev() is called
is buggy as well. I feel like it shouldn't be freeing "dev" because
that's a layering violation.
373 return -ENOMEM;
374 }
375
376 set_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags);
377 dev->power = newp;
378 } else if (to_nullb_device(item)->power && !newp) {
379 mutex_lock(&lock);
380 dev->power = newp;
381 null_del_dev(dev->nullb);
382 mutex_unlock(&lock);
383 clear_bit(NULLB_DEV_FL_UP, &dev->flags);
384 }
385
386 return count;
387 }
regards,
dan carpenter
reply other threads:[~2017-08-28 18:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20170828184901.ehaflki7emvhrb6a@mwanda \
--to=dan.carpenter@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=shli@fb.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