mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Davidlohr Bueso <dave@stgolabs.net>,
	Philippe Mikoyan <philippe.mikoyan@skat.systems>
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
	linux-kernel@vger.kernel.org, edgar.kaziakhmedov@virtuozzo.com
Subject: Re: [PATCH 2/2] ipc: Fix ipc data structures inconsistency
Date: Sat, 2 Dec 2017 07:03:30 +0100	[thread overview]
Message-ID: <bcf68a7f-d860-2c7e-69ed-341eb81c69e6@colorfullife.com> (raw)
In-Reply-To: <20171201172007.q2rqmo4jqaxb63tk@linux-n805>

Hi,

On 12/01/2017 06:20 PM, Davidlohr Bueso wrote:
> On Thu, 30 Nov 2017, Philippe Mikoyan wrote:
>
>> As described in the title, this patch fixes <ipc>id_ds inconsistency
>> when <ipc>ctl_stat runs concurrently with some ds-changing function,
>> e.g. shmat, msgsnd or whatever.
>>
>> For instance, if shmctl(IPC_STAT) is running concurrently with shmat,
>> following data structure can be returned:
>> {... shm_lpid = 0, shm_nattch = 1, ...}
>
The patch appears to be good. I'll try to perform some tests, but I'm 
not sure when I will be able to.
Especially: I don't know the shm code good enough to immediately check 
the change you make to nattach.

And, perhaps as a side information:
There appears to be a use-after-free in shm, I now got a 2nd mail from 
syzbot:
http://lkml.iu.edu/hypermail/linux/kernel/1702.3/02480.html


> Hmm yeah that's pretty fishy, also shm_atime = 0, no?
>
> So I think this patch is fine as we can obviously race at a user level.
> This is another justification for converting the ipc lock to rwlock;
> performance wise they are the pretty much the same (being queued)...
> but that's irrelevant to this patch. I like that you manage to do
> security and such checks still only under rcu, like all ipc calls
> work; *_stat() is no longer special.
>
I don't like rwlock, they add complexity without reducing the cache line 
pressure.

What I would like to try is to create a mutex_lock_rcu() function, and 
then convert everything to a mutex.

As pseudocode::
     rcu_lock();
     idr_lookup();
     mutex_trylock();
     if (failed) {
         getref();
         rcu_unlock();
         mutex_lock();
         putref();
     } else {
         rcu_unlock();
     }

Obviously, the getref then within the mutex framework, i.e. only if 
mutex_lock() really sleeps.
If the code in ipc gets significantly simpler, then perhaps convert it 
to an rw mutex.

  reply	other threads:[~2017-12-02  6:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30  6:12 [PATCH 0/2] ipc: Fix <ipc>ctl(..IPC_STAT..) bugs Philippe Mikoyan
2017-11-30  6:12 ` [PATCH 1/2] ipc/shm: Fix shm_nattch incorrect value Philippe Mikoyan
2017-11-30  6:12 ` [PATCH 2/2] ipc: Fix ipc data structures inconsistency Philippe Mikoyan
2017-12-01 17:20   ` Davidlohr Bueso
2017-12-02  6:03     ` Manfred Spraul [this message]
2017-12-02 14:43       ` Philippe Mikoyan
2017-12-03  1:37         ` Davidlohr Bueso

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=bcf68a7f-d860-2c7e-69ed-341eb81c69e6@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=edgar.kaziakhmedov@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philippe.mikoyan@skat.systems \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®