+ swapfile-avoid-null-pointer-dereference-in-swapon-when-s_bdev-is-null.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL
has been added to the -mm tree.  Its filename is
     swapfile-avoid-null-pointer-dereference-in-swapon-when-s_bdev-is-null.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: swapfile: avoid NULL pointer dereference in swapon when s_bdev is NULL
From: Suresh Jayaraman <sjayaraman@xxxxxxx>

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@xxxxxxx>
Cc: Jens Axboe <jens.axboe@xxxxxxxxxx>
Cc: Hugh Dickins <hugh.dickins@xxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 mm/swapfile.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff -puN mm/swapfile.c~swapfile-avoid-null-pointer-dereference-in-swapon-when-s_bdev-is-null mm/swapfile.c
--- a/mm/swapfile.c~swapfile-avoid-null-pointer-dereference-in-swapon-when-s_bdev-is-null
+++ a/mm/swapfile.c
@@ -1974,12 +1974,14 @@ SYSCALL_DEFINE2(swapon, const char __use
 		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);
_

Patches currently in -mm which might be from sjayaraman@xxxxxxx are

swapfile-avoid-null-pointer-dereference-in-swapon-when-s_bdev-is-null.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux