From: Manfred Spraul <manfred@colorfullife.com>
To: Davidlohr Bueso <davidlohr@hp.com>, akpm@linux-foundation.org
Cc: aswin@hp.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] ipc,msg: always respect MSG_NOERROR
Date: Mon, 19 May 2014 20:01:56 +0200 [thread overview]
Message-ID: <537A4714.1000009@colorfullife.com> (raw)
In-Reply-To: <1400436100.9463.4.camel@buesod1.americas.hpqcorp.net>
Hi Davidlohr, Hi Andrew,
On 05/18/2014 08:01 PM, Davidlohr Bueso wrote:
> On Sun, 2014-05-18 at 07:53 +0200, Manfred Spraul wrote:
>> On 05/13/2014 10:27 PM, Davidlohr Bueso wrote:
>>> When specifying the MSG_NOERROR flag, receivers can avoid returning
>>> error (E2BIG) and just truncate the message text, if it is too large.
>>>
>>> Currently, this logic is only respected when there are already pending
>>> messages in the queue.
>> Do you have a test case? The code should handle that
>> (See below)
Below you admit that the code works flawlessly.
I.e. The changelog misrepresents the patch as a bugfix, whereas it
actually is a cleanup.
The code is more or less 15 years old, cleanups are a good thing, but
NOT WITH A MISLEADING CHANGELOG!
(and unfortunately not the first time, you didn't mention that your
patch to modify SHMMAX also disabled SHMMIN).
>>> @@ -901,6 +907,7 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgfl
>>> list_add_tail(&msr_d.r_list, &msq->q_receivers);
>>> msr_d.r_tsk = current;
>>> msr_d.r_msgtype = msgtyp;
>>> + msr_d.r_msgflg = msgflg;
>>> msr_d.r_mode = mode;
>>> if (msgflg & MSG_NOERROR)
>>> msr_d.r_maxsize = INT_MAX;
>> ^^^^^^
>> This code should handle MSG_NOERROR:
>> If MSG_NOERROR is set, then maxsize is set to INT_MAX, therefore -E2BIG
>> should never be returned.
> Yeah, I noticed that, but I'd still prefer keeping the check, even if
> redundant. It's free and by keeping both scenarios where there are and
> aren't msg waiting in the queue the code becomes easier to read.
Why?
Preparation for porting to a noisy quantum computer, where we must check
for conditions twice?
Either you can pass the flags, or you treat MSG_NOERROR as "accept
messages up to size INT_MAX.
But not both.
A cleanup should *remove* code duplication and other complex parts, not
add additional code duplication.
Andrew:
Could you please drop the patch?
- The change log must be updated.
- The introduction of r_msgflg is questionable. r_maxsize=INT_MAX is
simpler than r_msgflg&MSG_NOERROR.
- The cleanup should be thoroughly tested, to verify that it doesn't
break something that is not tested by LTP.
--
Manfred
P.S.:
> + wake_up_process(msr->r_tsk);
>
> - return 1;
> - }
> + /*
> + * Ensure that the wakeup is visible before
> + * setting r_msg, as the receiving end depends
> + * on it. See lockless receive part 1 and 2 in
> + * do_msgrcv().
> + */
> + smp_mb();
> + msr->r_msg = msg;
No, it's not about visibility.
The issue is use-after-free:
- immediately after msr->r_msg = msg, the other task can return to user
space, call sys_exit() and then release the task struct
- wake_up_process(msr->r_tsk) then accesses already released memory.
On a virtualized hardware, this can happen (and did happen - either with
ipc/sem.c or ipc/msg.c, with S390. It was documented, it seems it got lost).
So a hands-off is required:
Writing r_msg must be the last write operation.
next prev parent reply other threads:[~2014-05-19 18:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 20:27 [PATCH -next 0/5] ipc,msg: fixes and updates Davidlohr Bueso
2014-05-13 20:27 ` [PATCH 1/5] ipc,msg: use current->state helpers Davidlohr Bueso
2014-05-17 17:55 ` Manfred Spraul
2014-05-13 20:27 ` [PATCH 2/5] ipc,msg: move some msgq ns code around Davidlohr Bueso
2014-05-17 17:57 ` Manfred Spraul
2014-05-13 20:27 ` [PATCH 3/5] ipc,msg: always respect MSG_NOERROR Davidlohr Bueso
2014-05-18 5:53 ` Manfred Spraul
2014-05-18 18:01 ` Davidlohr Bueso
2014-05-19 18:01 ` Manfred Spraul [this message]
2014-05-13 20:27 ` [PATCH 4/5] ipc,msg: document volatile r_msg Davidlohr Bueso
2014-05-18 6:08 ` Manfred Spraul
2014-05-13 20:27 ` [PATCH 5/5] ipc,msg: loosen check for full queue Davidlohr Bueso
2014-05-14 18:00 ` Manfred Spraul
2014-05-14 19:50 ` Davidlohr Bueso
2014-05-15 4:20 ` Manfred Spraul
2014-05-15 15:46 ` Davidlohr Bueso
2014-05-16 12:47 ` Michael Kerrisk (man-pages)
2014-05-18 18:16 ` 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=537A4714.1000009@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=akpm@linux-foundation.org \
--cc=aswin@hp.com \
--cc=davidlohr@hp.com \
--cc=linux-kernel@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