From: Andrew Morton <akpm@linux-foundation.org>
To: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Weijie Yang <weijie.yang.kh@gmail.com>,
Bob Liu <bob.liu@oracle.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Shaohua Li <shli@fusionio.com>, Minchan Kim <minchan@kernel.org>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] swap: fix set_blocksize race during swapon/swapoff
Date: Fri, 11 Oct 2013 12:02:26 -0700 [thread overview]
Message-ID: <20131011120226.1f4bb32569f370b57b841e79@linux-foundation.org> (raw)
In-Reply-To: <1381485262-16792-1-git-send-email-k.kozlowski@samsung.com>
(cc Hugh)
On Fri, 11 Oct 2013 11:54:22 +0200 Krzysztof Kozlowski <k.kozlowski@samsung.com> wrote:
> Swapoff used old_block_size from swap_info which could be overwritten by
> concurrent swapon.
>
> Reported-by: Weijie Yang <weijie.yang.kh@gmail.com>
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> ---
> mm/swapfile.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 3963fc2..de7c904 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1824,6 +1824,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> struct filename *pathname;
> int i, type, prev;
> int err;
> + unsigned int old_block_size;
>
> if (!capable(CAP_SYS_ADMIN))
> return -EPERM;
> @@ -1914,6 +1915,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> }
>
> swap_file = p->swap_file;
> + old_block_size = p->old_block_size;
> p->swap_file = NULL;
> p->max = 0;
> swap_map = p->swap_map;
> @@ -1938,7 +1940,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> inode = mapping->host;
> if (S_ISBLK(inode->i_mode)) {
> struct block_device *bdev = I_BDEV(inode);
> - set_blocksize(bdev, p->old_block_size);
> + set_blocksize(bdev, old_block_size);
> blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
> } else {
> mutex_lock(&inode->i_mutex);
I find it worrying that a swapon can run concurrently with any of this
swapoff code. It just seem to be asking for trouble and the code
really isn't set up for this and races here will be poorly tested for
I'm wondering if we should just extend swapon_mutex a lot and eliminate
the concurrency?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-10-11 19:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-11 9:54 [PATCH] swap: fix set_blocksize race during swapon/swapoff Krzysztof Kozlowski
2013-10-11 18:55 ` Andrew Morton
2013-10-14 10:19 ` Krzysztof Kozlowski
2013-10-11 19:02 ` Andrew Morton [this message]
2013-10-14 9:47 ` Krzysztof Kozlowski
2013-10-15 9:56 ` Hugh Dickins
2013-10-15 9:45 ` Hugh Dickins
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=20131011120226.1f4bb32569f370b57b841e79@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bob.liu@oracle.com \
--cc=hughd@google.com \
--cc=k.kozlowski@samsung.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=shli@fusionio.com \
--cc=weijie.yang.kh@gmail.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 NNTP newsgroup(s).