public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Doug Ledford <dledford@redhat.com>
Cc: linux-kernel@vger.kernel.org, sfr@canb.auug.org.au,
	Manfred Spraul <manfred@colorfullife.com>
Subject: Re: [Patch 2/4] ipc/mqueue: correct mq_attr_ok test
Date: Tue, 1 May 2012 12:34:30 -0700	[thread overview]
Message-ID: <20120501123430.63f4bf85.akpm@linux-foundation.org> (raw)
In-Reply-To: <4a62cbda48cf31ca796f37fa8904f314f643db57.1335894230.git.dledford@redhat.com>

On Tue,  1 May 2012 13:50:53 -0400
Doug Ledford <dledford@redhat.com> wrote:

> While working on the other parts of the mqueue stuff, I noticed that
> the calculation for overflow in mq_attr_ok didn't actually match
> reality (this is especially true since my last patch which changed
> how we account memory slightly).

Please cc Manfred on mqueue things?  He still watches ;)

> In particular, we used to test for overflow using:
>   msgs * msgsize + msgs * sizeof(struct msg_msg *)
> 
> That was never really correct because each message we allocate via
> load_msg() is actually a struct msg_msg followed by the data for
> the message (and if struct msg_msg + data exceeds PAGE_SIZE we end
> up allocating struct msg_msgseg structs too, but accounting for them
> would get really tedious, so let's ignore those...they're only a
> pointer in size anyway).  This patch updates the calculation to be
> more accurate in regards to maximum possible memory consumption by the
> mqueue.
> 
> ...
>
> --- a/ipc/mqueue.c
> +++ b/ipc/mqueue.c
>
> ...
>
> @@ -684,8 +686,11 @@ static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
>  	/* check for overflow */
>  	if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg)
>  		return 0;
> -	if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize
> -	    + sizeof (struct msg_msg *))) <
> +	mq_treesize = attr->mq_maxmsg * sizeof(struct msg_msg) +
> +		min_t(unsigned int, attr->mq_maxmsg, MQ_PRIO_MAX) *
> +		sizeof(struct posix_msg_tree_node);
> +	if ((unsigned long)(attr->mq_maxmsg * attr->mq_msgsize +
> +			    mq_treesize) <
>  	    (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize))
>  		return 0;
>  	return 1;

That's a bit of a mouthful.  Does this look OK?

--- a/ipc/mqueue.c~ipc-mqueue-correct-mq_attr_ok-test-fix
+++ a/ipc/mqueue.c
@@ -672,7 +672,8 @@ static void remove_notification(struct m
 static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
 {
 	int mq_treesize;
-
+	unsigned long total_size;
+	
 	if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
 		return 0;
 	if (capable(CAP_SYS_RESOURCE)) {
@@ -690,9 +691,8 @@ static int mq_attr_ok(struct ipc_namespa
 	mq_treesize = attr->mq_maxmsg * sizeof(struct msg_msg) +
 		min_t(unsigned int, attr->mq_maxmsg, MQ_PRIO_MAX) *
 		sizeof(struct posix_msg_tree_node);
-	if ((unsigned long)(attr->mq_maxmsg * attr->mq_msgsize +
-			    mq_treesize) <
-	    (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize))
+	total_size = attr->mq_maxmsg * attr->mq_msgsize;
+	if (total_size + mq_treesize < total_size)
 		return 0;
 	return 1;
 }
_


  reply	other threads:[~2012-05-01 19:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-01 17:50 [Patch 0/4] ipc/mqueue improvements Doug Ledford
2012-05-01 17:50 ` [Patch 1/4] ipc/mqueue: improve performance of send/recv Doug Ledford
2012-05-01 17:50   ` [Patch 2/4] ipc/mqueue: correct mq_attr_ok test Doug Ledford
2012-05-01 19:34     ` Andrew Morton [this message]
2012-05-01 19:38       ` Doug Ledford
2012-05-01 17:50   ` [Patch 3/4] ipc/mqueue: strengthen checks on mqueue creation Doug Ledford
2012-05-01 20:01     ` KOSAKI Motohiro
2012-05-01 20:11       ` Doug Ledford
2012-05-01 20:18         ` KOSAKI Motohiro
2012-05-01 23:02           ` Doug Ledford
2012-05-01 23:04             ` KOSAKI Motohiro
2012-05-01 23:11               ` Andrew Morton
2012-05-01 17:50   ` [Patch 4/4] tools/selftests: add mq_perf_tests Doug Ledford
2012-05-01 19:53     ` Andrew Morton
2012-05-01 20:14       ` Doug Ledford
2012-05-03  9:21   ` [Patch 1/4] ipc/mqueue: improve performance of send/recv Dan Carpenter
2012-05-03 13:03     ` Doug Ledford
2012-05-03 10:05   ` Nick Piggin

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=20120501123430.63f4bf85.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=dledford@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=sfr@canb.auug.org.au \
    /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