All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Kinsbursky <skinsbursky@parallels.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dave Jones <davej@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@surriel.com>,
	Davidlohr Bueso <davidlohr.bueso@hp.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	<hhuang@redhat.com>, "Low, Jason" <jason.low2@hp.com>,
	Michel Lespinasse <walken@google.com>,
	Larry Woodman <lwoodman@redhat.com>,
	"Vinod, Chegu" <chegu_vinod@hp.com>,
	Peter Hurley <peter@hurleysoftware.com>,
	"sds@tycho.nsa.gov" <sds@tycho.nsa.gov>
Subject: Re: ipc,sem: sysv semaphore scalability
Date: Mon, 1 Apr 2013 11:40:51 +0400	[thread overview]
Message-ID: <51593A03.4050407@parallels.com> (raw)
In-Reply-To: <CA+55aFwA6CpODkJwHFd59EbNxOrP-FHM+xG8Xcgeni2DBotGPA@mail.gmail.com>

29.03.2013 22:43, Linus Torvalds пишет:
> On Fri, Mar 29, 2013 at 9:17 AM, Dave Jones<davej@redhat.com>  wrote:
>> >
>> >Now that I have that reverted, I'm not seeing msgrcv traces any more, but
>> >I've started seeing this..
>> >
>> >general protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
> Do you have CONFIG_CHECKPOINT_RESTORE enabled? Does it go away if you
> disable it?
>
> I think I foud at least one bug in the MSG_COPY stuff: it leaks the
> "copy" allocation if
>
>      mode == SEARCH_LESSEQUAL
>

Hello, Linus.
Sorry, but I don't see copy allocation leak.
Dummy message is allocated always in msgflg has MSG_COPY flag being set.
Also prepare_copy() use msgtyp as a message number to copy and thus set it to 0.

> but maybe I'm misreading it. And that shouldn't cause the problem you
> see, but it's indicative of how badly tested and thought through the
> MSG_COPY code is.
>
> Totally UNTESTED leak fix appended. Stanislav?
>

I don't see, how this patch can help. And we should not release it until copy is
done in msg_handler, because msg is equal to copy.

Dummy copy message is release either by free_copy() (if msg is error) or
free_msg().

But there are two issues here definitely:

1) Poor SELinux support for message
copying. This issue was addressed by Stephen Smalley here:

https://lkml.org/lkml/2013/2/6/663

But look like he didn't sent the patch to Andrew.

2) Copy leak and queue corruption in case of
copy message wasn't found (this was mentioned by Peter in another thread; thanks for
catching this, Peter!), because msg will be a valid pointer and all the "message copy"
clean up logic doesn't work.

I like Peter's cleanup and fix series.  But if it looks like too much changes
for this old code, I have another small patch, which should fix the issue:

     ipc: set msg back to -EAGAIN if copy wasn't performed

     Make sure, that msg pointer is set back to error value in case of MSG_COPY
     flag is set and desired message to copy wasn't found. This garantees, that msg
     is either a error pointer or a copy address.
     Otherwise last message in queue will be freed without unlinking from queue
     (which leads to memory corruption) plus dummy allocated copy won't be released.

     Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>

diff --git a/ipc/msg.c b/ipc/msg.c
index 31cd1bf..fede1d0 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -872,6 +872,7 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
                                                         goto out_unlock;
                                                 break;
                                         }
+                                       msg = ERR_PTR(-EAGAIN);
                                 } else
                                         break;
                                 msg_counter++;

>                       Linus
>
>
> patch.diff
>
>
>   ipc/msg.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/ipc/msg.c b/ipc/msg.c
> index 31cd1bf6af27..b841508556cb 100644
> --- a/ipc/msg.c
> +++ b/ipc/msg.c
> @@ -870,6 +870,7 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
>   						msg = copy_msg(msg, copy);
>   						if (IS_ERR(msg))
>   							goto out_unlock;
> +						copy = NULL;
>   						break;
>   					}
>   				} else
> @@ -976,10 +977,9 @@ out_unlock:
>   			break;
>   		}
>   	}
> -	if (IS_ERR(msg)) {
> -		free_copy(copy);
> +	free_copy(copy);
> +	if (IS_ERR(msg))
>   		return PTR_ERR(msg);
> -	}
>
>   	bufsz = msg_handler(buf, msg, bufsz);
>   	free_msg(msg);
>


-- 
Best regards,
Stanislav Kinsbursky

  parent reply	other threads:[~2013-04-01  7:43 UTC|newest]

Thread overview: 129+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 19:55 ipc,sem: sysv semaphore scalability Rik van Riel
2013-03-20 19:55 ` [PATCH 1/7] ipc: remove bogus lock comment for ipc_checkid Rik van Riel
2013-03-20 19:55 ` [PATCH 2/7] ipc: introduce obtaining a lockless ipc object Rik van Riel
2013-03-20 19:55 ` [PATCH 3/7] ipc: introduce lockless pre_down ipcctl Rik van Riel
2013-03-20 19:55 ` [PATCH 4/7] ipc,sem: do not hold ipc lock more than necessary Rik van Riel
2013-03-20 19:55 ` [PATCH 5/7] ipc,sem: open code and rename sem_lock Rik van Riel
2013-03-22  1:14   ` Davidlohr Bueso
2013-03-20 19:55 ` [PATCH 6/7] ipc,sem: have only one list in struct sem_queue Rik van Riel
2013-03-22  1:14   ` Davidlohr Bueso
2013-03-20 19:55 ` [PATCH 7/7] ipc,sem: fine grained locking for semtimedop Rik van Riel
2013-03-22  1:14   ` Davidlohr Bueso
2013-03-22 23:01   ` Michel Lespinasse
2013-03-22 23:38     ` Rik van Riel
2013-03-22 23:42     ` [PATCH 7/7 part3] fix for sem_lock Rik van Riel
2013-03-20 20:49 ` ipc,sem: sysv semaphore scalability Linus Torvalds
2013-03-20 20:56   ` Linus Torvalds
2013-03-20 20:57   ` Davidlohr Bueso
2013-03-21 21:10 ` Andrew Morton
2013-03-21 21:47   ` Peter Hurley
2013-03-21 21:50   ` Peter Hurley
2013-03-21 22:01     ` Andrew Morton
2013-03-22  3:38       ` Rik van Riel
2013-03-26 19:28   ` Dave Jones
2013-03-26 19:43     ` Andrew Morton
2013-03-29 16:17       ` Dave Jones
2013-03-29 18:00         ` Linus Torvalds
2013-03-29 18:04           ` Dave Jones
2013-03-29 18:10             ` Linus Torvalds
2013-03-29 18:43         ` Linus Torvalds
2013-03-29 19:06           ` Dave Jones
2013-03-29 19:13             ` Linus Torvalds
2013-03-29 19:26             ` Linus Torvalds
2013-03-29 19:36               ` Peter Hurley
2013-04-02 16:08                 ` Sasha Levin
2013-04-02 17:24                   ` Linus Torvalds
2013-04-02 17:52                   ` Linus Torvalds
2013-04-02 19:53                     ` Sasha Levin
2013-04-02 20:00                       ` Dave Jones
2013-03-29 19:33           ` Peter Hurley
2013-03-29 19:54             ` Linus Torvalds
2013-04-01  7:40           ` Stanislav Kinsbursky [this message]
2013-03-29 20:41         ` Linus Torvalds
2013-03-29 21:12           ` Linus Torvalds
2013-03-29 23:16             ` Linus Torvalds
2013-03-30  1:36               ` Emmanuel Benisty
2013-03-30  2:08                 ` Davidlohr Bueso
2013-03-30  3:02                   ` Emmanuel Benisty
2013-03-30  3:46                     ` Linus Torvalds
2013-03-30  4:33                       ` Emmanuel Benisty
2013-03-30  5:10                         ` Linus Torvalds
2013-03-30  5:57                           ` Emmanuel Benisty
2013-03-30 17:22                             ` Linus Torvalds
2013-03-31  2:38                               ` Emmanuel Benisty
2013-03-31  5:01                         ` Davidlohr Bueso
2013-03-31 13:45                           ` Rik van Riel
2013-03-31 17:10                             ` Linus Torvalds
2013-03-31 17:02                           ` Emmanuel Benisty
2013-03-30  2:09                 ` Linus Torvalds
2013-03-30  2:55                   ` Davidlohr Bueso
2013-03-29 19:01       ` Dave Jones
2013-05-03 15:03         ` Peter Hurley
2013-03-22  1:12 ` Davidlohr Bueso
2013-03-22  1:23   ` Linus Torvalds
2013-03-22  3:40     ` Rik van Riel
2013-03-22  7:30 ` Mike Galbraith
2013-03-22 11:04 ` Emmanuel Benisty
2013-03-22 15:37   ` Linus Torvalds
2013-03-23  3:19     ` Emmanuel Benisty
2013-03-23 19:45       ` Linus Torvalds
2013-03-24 13:46         ` Emmanuel Benisty
2013-03-24 17:10           ` Linus Torvalds
2013-03-25 13:47             ` Emmanuel Benisty
2013-03-25 14:00               ` Rik van Riel
2013-03-25 14:03                 ` Rik van Riel
2013-03-25 15:20                   ` Emmanuel Benisty
2013-03-25 15:53                     ` Rik van Riel
2013-03-25 17:09                       ` Emmanuel Benisty
2013-03-25 14:01               ` Rik van Riel
2013-03-25 14:21                 ` Emmanuel Benisty
2013-03-26 17:59               ` Davidlohr Bueso
2013-03-26 18:14                 ` Rik van Riel
2013-03-26 18:35                 ` Andrew Morton
2013-04-16 23:30                   ` Andrew Morton
2013-05-04 15:55       ` Jörn Engel
2013-05-04 18:12         ` Borislav Petkov
2013-05-06 14:47           ` Jörn Engel
2013-03-22 17:51 ` Davidlohr Bueso
2013-03-25 20:21 ` Sasha Levin
2013-03-25 20:38   ` [PATCH -mm -next] ipc,sem: fix lockdep false positive Rik van Riel
2013-03-25 21:42     ` Michel Lespinasse
2013-03-25 21:51       ` Michel Lespinasse
2013-03-25 21:56         ` Sasha Levin
2013-03-25 21:52       ` Sasha Levin
2013-03-26 13:19       ` Peter Zijlstra
2013-03-26 13:40         ` Michel Lespinasse
2013-03-26 14:27           ` Peter Zijlstra
2013-03-26 15:19             ` Rik van Riel
2013-03-27  8:40               ` Peter Zijlstra
2013-03-27  8:42               ` Peter Zijlstra
2013-03-27 11:22                 ` Michel Lespinasse
2013-03-27 12:02                   ` Peter Zijlstra
2013-03-27 20:00                 ` Rik van Riel
2013-03-28 20:23                 ` [PATCH v2 " Rik van Riel
2013-03-29  2:50                   ` Michel Lespinasse
2013-03-29  9:57                     ` Peter Zijlstra
2013-03-29 13:21                       ` Michel Lespinasse
2013-03-29 12:07                     ` Rik van Riel
2013-03-29 13:08                       ` Michel Lespinasse
2013-03-29 13:24                         ` Rik van Riel
2013-03-29 13:55                     ` [PATCH v3 " Rik van Riel
2013-03-29 13:59                       ` Michel Lespinasse
2013-03-26 14:25         ` [PATCH " Rik van Riel
2013-03-26 17:33 ` ipc,sem: sysv semaphore scalability Sasha Levin
2013-03-26 17:51   ` Davidlohr Bueso
2013-03-26 18:07     ` Sasha Levin
2013-03-26 18:17       ` Rik van Riel
2013-03-26 20:00       ` [PATCH -mm -next] ipc,sem: untangle RCU locking with find_alloc_undo Rik van Riel
2013-04-05  4:38         ` Mike Galbraith
2013-04-05 13:21           ` Rik van Riel
2013-04-05 16:26             ` Mike Galbraith
2013-04-16 12:37             ` Mike Galbraith
2013-03-26 17:55   ` ipc,sem: sysv semaphore scalability Paul E. McKenney
2013-03-28 15:32   ` [PATCH -mm -next] ipc,sem: untangle RCU locking with find_alloc_undo Rik van Riel
2013-03-28 21:05     ` Davidlohr Bueso
2013-03-29  1:00     ` Michel Lespinasse
2013-03-29  1:14       ` Sasha Levin
2013-03-30 13:35     ` Sasha Levin
2013-03-31  1:30       ` Rik van Riel
2013-03-31  4:09         ` 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=51593A03.4050407@parallels.com \
    --to=skinsbursky@parallels.com \
    --cc=akpm@linux-foundation.org \
    --cc=chegu_vinod@hp.com \
    --cc=davej@redhat.com \
    --cc=davidlohr.bueso@hp.com \
    --cc=hhuang@redhat.com \
    --cc=jason.low2@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwoodman@redhat.com \
    --cc=peter@hurleysoftware.com \
    --cc=riel@surriel.com \
    --cc=sds@tycho.nsa.gov \
    --cc=torvalds@linux-foundation.org \
    --cc=walken@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.