mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Svenning Sørensen" <sss@secomea.dk>
Cc: linux-kernel@vger.kernel.org, Peter Hurley <peter@hurleysoftware.com>
Subject: Re: [PATCH] IPC: bugfix for msgrcv with msgtyp < 0
Date: Mon, 26 Aug 2013 13:41:59 -0700	[thread overview]
Message-ID: <20130826134159.d033956c339cbd0bb7cb6f7f@linux-foundation.org> (raw)
In-Reply-To: <52189CB1.9030806@secomea.dk>

On Sat, 24 Aug 2013 13:44:49 +0200 Svenning S__rensen <sss@secomea.dk> wrote:

> According to 'man msgrcv':
> "If msgtyp is less than 0, the first message of the lowest type that is less
> than or equal to the absolute value of msgtyp shall be received."
> 
> Bug: The kernel only returns a message if its type is 1; other messages with
> type < abs(msgtype) will never get returned.
> 
> Fix: After having traversed the list to find the first message with the
> lowest type, we need to actually return that message.
> 
> Signed-off-by: Svenning Soerensen <sss@secomea.dk>
> 
> diff --git a/ipc/msg.c b/ipc/msg.c
> index bd60d7e..9f29d9e 100644
> --- a/ipc/msg.c
> +++ b/ipc/msg.c
> @@ -839,7 +839,7 @@ static inline void free_copy(struct msg_msg *copy)
>   
>   static struct msg_msg *find_msg(struct msg_queue *msq, long *msgtyp, int mode)
>   {
> -	struct msg_msg *msg;
> +	struct msg_msg *msg, *found = NULL;
>   	long count = 0;
>   
>   	list_for_each_entry(msg, &msq->q_messages, m_list) {
> @@ -848,6 +848,7 @@ static struct msg_msg *find_msg(struct msg_queue *msq, long *msgtyp, int mode)
>   					       *msgtyp, mode)) {
>   			if (mode == SEARCH_LESSEQUAL && msg->m_type != 1) {
>   				*msgtyp = msg->m_type - 1;
> +				found = msg;

Should we continue the search in this case, or should the code
immediately return this message?

>   			} else if (mode == SEARCH_NUMBER) {
>   				if (*msgtyp == count)
>   					return msg;
> @@ -857,7 +858,7 @@ static struct msg_msg *find_msg(struct msg_queue *msq, long *msgtyp, int mode)
>   		}
>   	}
>   
> -	return ERR_PTR(-EAGAIN);
> +	return found ?: ERR_PTR(-EAGAIN);
>   }
>   
>   long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgflg,

      parent reply	other threads:[~2013-08-26 20:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 11:44 Svenning Sørensen
2013-08-24 12:49 ` Peter Hurley
2013-08-26 20:42   ` Andrew Morton
2013-08-26 20:59     ` Peter Hurley
2013-08-26 20:41 ` Andrew Morton [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=20130826134159.d033956c339cbd0bb7cb6f7f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter@hurleysoftware.com \
    --cc=sss@secomea.dk \
    /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

Powered by JetHome