mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH < v3.10] ipc/msg: fix race around refcount
Date: Sun, 06 Apr 2014 14:00:44 +0100	[thread overview]
Message-ID: <1396789244.22689.121.camel@deadeye.wl.decadent.org.uk> (raw)
In-Reply-To: <20140326101218.11221.74072.stgit@buzz>

[-- Attachment #1: Type: text/plain, Size: 1603 bytes --]

On Wed, 2014-03-26 at 14:12 +0400, Konstantin Khlebnikov wrote:
> In older kernels (before v3.10) ipc_rcu_hdr->refcount was non-atomic int.
> There was possuble double-free bug: do_msgsnd() calls ipc_rcu_putref() under
> msq->q_perm->lock and RCU, while freequeue() calls it while it holds only
> 'rw_mutex', so there is no sinchronization between them. Two function
> decrements '2' non-atomically, they both can get '0' as result.
[...]
> In the mainline this has been fixed in v3.10 indirectly in commmit
> 6062a8dc0517bce23e3c2f7d2fea5e22411269a3
> ("ipc,sem: fine grained locking for semtimedop") by Rik van Riel.
> That commit optimized locking and converted refcount into atomic.
> 
> I'm not sure that anybody should care about this bug: it's very-very unlikely
> and no longer exists in actual mainline. I've found this just by looking into
> the code, probably this never happens in real life.

Queued up for 3.2, thanks.

Ben.

> Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
> ---
>  ipc/msg.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/ipc/msg.c b/ipc/msg.c
> index 7385de2..25f1a61 100644
> --- a/ipc/msg.c
> +++ b/ipc/msg.c
> @@ -296,7 +296,9 @@ static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
>  	}
>  	atomic_sub(msq->q_cbytes, &ns->msg_bytes);
>  	security_msg_queue_free(msq);
> +	ipc_lock_by_ptr(&msq->q_perm);
>  	ipc_rcu_putref(msq);
> +	ipc_unlock(&msq->q_perm);
>  }
>  
>  /*

-- 
Ben Hutchings
I say we take off; nuke the site from orbit.  It's the only way to be sure.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

      parent reply	other threads:[~2014-04-06 13:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-26 10:12 Konstantin Khlebnikov
2014-03-31  9:09 ` Luís Henriques
2014-04-06 13:00 ` Ben Hutchings [this message]

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=1396789244.22689.121.camel@deadeye.wl.decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=k.khlebnikov@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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®