From: Jens Axboe <jens.axboe@oracle.com>
To: Suresh Jayaraman <sjayaraman@suse.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Hugh Dickins <hugh.dickins@tiscali.co.uk>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL
Date: Wed, 30 Sep 2009 08:57:22 +0200 [thread overview]
Message-ID: <20090930065722.GN23126@kernel.dk> (raw)
In-Reply-To: <4AC1FC41.2060807@suse.de>
On Tue, Sep 29 2009, Suresh Jayaraman wrote:
> While testing Swap over NFS patchset, I noticed an oops that was triggered
> during swapon. Investigating further, the NULL pointer deference is due to the
> SSD device check/optimization in the swapon code that assumes s_bdev could never
> be NULL.
>
> inode->i_sb->s_bdev could be NULL in a few cases. For e.g. one such case is
> loopback NFS mount, there could be others as well. Fix this by ensuring s_bdev
> is not NULL before we try to deference s_bdev.
>
> Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de>
> ---
> mm/swapfile.c | 12 +++++++-----
> 1 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 4de7f02..a1bc6b9 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1974,12 +1974,14 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> goto bad_swap;
> }
>
> - if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
> - p->flags |= SWP_SOLIDSTATE;
> - p->cluster_next = 1 + (random32() % p->highest_bit);
> + if (p->bdev) {
> + if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
> + p->flags |= SWP_SOLIDSTATE;
> + p->cluster_next = 1 + (random32() % p->highest_bit);
> + }
> + if (discard_swap(p) == 0)
> + p->flags |= SWP_DISCARDABLE;
> }
> - if (discard_swap(p) == 0)
> - p->flags |= SWP_DISCARDABLE;
>
> mutex_lock(&swapon_mutex);
> spin_lock(&swap_lock);
Thanks for the patch, looks correct.
--
Jens Axboe
next prev parent reply other threads:[~2009-09-30 6:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-29 12:23 [PATCH] swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL Suresh Jayaraman
2009-09-30 6:57 ` Jens Axboe [this message]
2009-10-01 10:07 ` Hugh Dickins
2009-10-01 11:30 ` Suresh Jayaraman
2009-10-01 11:53 ` Hugh Dickins
2009-10-01 12:07 ` Suresh Jayaraman
2009-10-06 21:03 ` Hugh Dickins
2009-10-07 3:55 ` Suresh Jayaraman
2009-10-21 12:43 ` Suresh Jayaraman
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=20090930065722.GN23126@kernel.dk \
--to=jens.axboe@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=hugh.dickins@tiscali.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=sjayaraman@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.