From: Davidlohr Bueso <dave@stgolabs.net>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Dmitry Vyukov <dvyukov@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
dave.hansen@linux.intel.com, Hugh Dickins <hughd@google.com>,
Joe Perches <joe@perches.com>,
sds@tycho.nsa.gov, Oleg Nesterov <oleg@redhat.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Rik van Riel <riel@redhat.com>,
mhocko@suse.cz, gang.chen.5i5j@gmail.com,
Peter Feiner <pfeiner@google.com>,
aarcange@redhat.com, "linux-mm@kvack.org" <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
syzkaller@googlegroups.com, Kostya Serebryany <kcc@google.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@google.com>,
Sasha Levin <sasha.levin@oracle.com>
Subject: Re: GPF in shm_lock ipc
Date: Mon, 12 Oct 2015 11:55:33 -0700 [thread overview]
Message-ID: <20151012185533.GD3170@linux-uzut.site> (raw)
In-Reply-To: <20151012181040.GC6447@node>
On Mon, 12 Oct 2015, Kirill A. Shutemov wrote:
>On Mon, Oct 12, 2015 at 10:49:45AM -0700, Davidlohr Bueso wrote:
>> diff --git a/ipc/shm.c b/ipc/shm.c
>> index 4178727..9615f19 100644
>> --- a/ipc/shm.c
>> +++ b/ipc/shm.c
>> @@ -385,9 +385,25 @@ static struct mempolicy *shm_get_policy(struct vm_area_struct *vma,
>> static int shm_mmap(struct file *file, struct vm_area_struct *vma)
>> {
>> - struct shm_file_data *sfd = shm_file_data(file);
>> + struct file *vma_file = vma->vm_file;
>> + struct shm_file_data *sfd = shm_file_data(vma_file);
>> + struct ipc_ids *ids = &shm_ids(sfd->ns);
>> + struct kern_ipc_perm *shp;
>> int ret;
>> + rcu_read_lock();
>> + shp = ipc_obtain_object_check(ids, sfd->id);
>> + if (IS_ERR(shp)) {
>> + ret = -EINVAL;
>> + goto err;
>> + }
>> +
>> + if (!ipc_valid_object(shp)) {
>> + ret = -EIDRM;
>> + goto err;
>> + }
>> + rcu_read_unlock();
>> +
>
>Hm. Isn't it racy? What prevents IPC_RMID from happening after this point?
Nothing, but that is later caught by shm_open() doing similar checks. We
basically end up doing a check between ->mmap() calls, which is fair imho.
Note that this can occur anywhere in ipc as IPC_RMID is a user request/cmd,
and we try to respect it -- thus you can argue this race anywhere, which is
why we have EIDRM/EINVL. Ultimately the user should not be doing such hacks
_anyway_. So I'm not really concerned about it.
Another similar alternative would be perhaps to make shm_lock() return an
error, and thus propagate that error to mmap return. That way we would have
a silent way out of the warning scenario (afterward we cannot race as we
hold the ipc object lock). However, the users would now have to take this
into account...
[validity check lockless]
->mmap()
[validity check lock]
>Shouldn't we bump shm_nattch here? Or some other refcount?
At least not shm_nattach, as that would acknowledge a new attachment after
a valid IPC_RMID. But the problem is also with how we check for marked for
deletion segments -- ipc_valid_object() checking the deleted flag. As such,
we always rely on explicitly checking against the deleted flag.
--
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:[~2015-10-12 18:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-12 9:55 GPF in shm_lock ipc Dmitry Vyukov
2015-10-12 11:41 ` Vlastimil Babka
2015-10-12 11:44 ` Dmitry Vyukov
2015-10-12 12:27 ` Kirill A. Shutemov
2015-10-12 17:49 ` Davidlohr Bueso
2015-10-12 18:10 ` Kirill A. Shutemov
2015-10-12 18:55 ` Davidlohr Bueso [this message]
2015-10-13 3:18 ` Davidlohr Bueso
2015-10-13 12:30 ` Kirill A. Shutemov
2015-10-29 15:33 ` Dmitry Vyukov
2015-11-05 14:23 ` Kirill A. Shutemov
2015-12-21 15:44 ` Dmitry Vyukov
2016-01-02 11:33 ` Manfred Spraul
2016-01-02 12:19 ` Dmitry Vyukov
2016-01-02 15:58 ` Manfred Spraul
2016-02-02 3:25 ` Andrew Morton
2016-02-02 21:32 ` Dmitry Vyukov
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=20151012185533.GD3170@linux-uzut.site \
--to=dave@stgolabs.net \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@google.com \
--cc=dave.hansen@linux.intel.com \
--cc=dvyukov@google.com \
--cc=gang.chen.5i5j@gmail.com \
--cc=glider@google.com \
--cc=hughd@google.com \
--cc=joe@perches.com \
--cc=kcc@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=oleg@redhat.com \
--cc=pfeiner@google.com \
--cc=riel@redhat.com \
--cc=sasha.levin@oracle.com \
--cc=sds@tycho.nsa.gov \
--cc=syzkaller@googlegroups.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).