From: Suresh Jayaraman <sjayaraman@suse.de>
To: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rafael Wysocki <rjw@sisk.pl>, Jens Axboe <axboe@kernel.dk>,
LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL
Date: Thu, 01 Oct 2009 17:00:42 +0530 [thread overview]
Message-ID: <4AC492E2.7060205@suse.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0910011052330.7682@sister.anvils>
Hugh Dickins wrote:
> On Tue, 29 Sep 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>
>
> Acked-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
>
> Thanks a lot for that: sorry to say I was ignorant of the possibility.
>
> This is only an issue with an out-of-tree patch, is that correct?
Yes, it was reproducible only with an out-of-tree patch.
> I'd like it to be fixed anyway, but if there's a way in which it can
> happen in unpatched 2.6.31, then we ought to send the fix to -stable.
>
> I've added Rafael to the Cc, because CONFIG_HIBERNATION's swap_type_of()
> looks also dangerous in this respect - and especially where it does that
> "if (bdev == sis->bdev) {" match, I think it's assuming NULL bdev cannot
> match against anything.
Yeah, perhaps. I stumbled upon one more of such error - a NULL pointer
dereference in blkdev_issue_discard() called from get_swap_page() when I ran
memhog, a simple program to generate a memory hog with Swap over NFS patches.
The call sequence is add_to_swap() -> get_swap_page() -> scan_swap_map()
-> discard_swap_cluster() -> blkdev_issue_discard().
Wrapping the code around a NULL check fixes the Oops for me.
Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de>
---
mm/swapfile.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 4de7f02..51f39cf 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -160,11 +160,13 @@ static int discard_swap(struct swap_info_struct *si)
continue;
}
- err = blkdev_issue_discard(si->bdev, start_block,
- nr_blocks, GFP_KERNEL,
- DISCARD_FL_BARRIER);
- if (err)
- break;
+ if (si->bdev) {
+ err = blkdev_issue_discard(si->bdev, start_block,
+ nr_blocks, GFP_KERNEL,
+ DISCARD_FL_BARRIER);
+ if (err)
+ break;
+ }
cond_resched();
}
@@ -200,10 +202,12 @@ static void discard_swap_cluster(struct swap_info_struct *si,
start_block <<= PAGE_SHIFT - 9;
nr_blocks <<= PAGE_SHIFT - 9;
- if (blkdev_issue_discard(si->bdev, start_block,
+ if (si->bdev) {
+ if (blkdev_issue_discard(si->bdev, start_block,
nr_blocks, GFP_NOIO,
DISCARD_FL_BARRIER))
- break;
+ break;
+ }
}
lh = se->list.next;
next prev parent reply other threads:[~2009-10-01 11:29 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
2009-10-01 10:07 ` Hugh Dickins
2009-10-01 11:30 ` Suresh Jayaraman [this message]
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=4AC492E2.7060205@suse.de \
--to=sjayaraman@suse.de \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=hugh.dickins@tiscali.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@sisk.pl \
/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.