All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang F T <chen.gang.flying.transformer@gmail.com>
To: Christoph Lameter <cl@linux.com>
Cc: Chen Gang <gang.chen@asianux.com>,
	Pekka Enberg <penberg@kernel.org>,
	mpm@selenic.com, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] mm/slub.c: add parameter length checking for alloc_loc_track()
Date: Fri, 19 Jul 2013 08:05:53 +0800	[thread overview]
Message-ID: <51E882E1.4000504@gmail.com> (raw)
In-Reply-To: <0000013ff2076fb0-b52e0245-8fb5-4842-b0dd-d812ce2c9f62-000000@email.amazonses.com>

On 07/18/2013 09:45 PM, Christoph Lameter wrote:
> On Thu, 18 Jul 2013, Chen Gang wrote:
> 
>> > Hmm... when anybody says "need respect original authors' willing and
>> > opinions", I think it often means we have found the direct issue, but
>> > none of us find the root issue.
> Is there an actual problem / failure being addressed by this patch?
> 

No, at least, this patch (add parameter length checking) is useless.

>> > e.g. for our this case:
>> >   the direct issue is:
>> >     "whether need check the length with 'max' parameter".
>> >   but maybe the root issue is:
>> >     "whether use 'size' as related parameter name instead of 'max'".
>> >     in alloc_loc_track(), 'max' just plays the 'size' role.
> "max" determines the size of the loc_track structure. So these can
> roughly mean the same thing.


Yes, "'max' can roughly mean the same thing", but they are still a
little different.

'max' also means: "the caller tells callee: I have told you the
maximize buffer length, so I need not check the buffer length to be
sure of no memory overflow, you need be sure of it".

'size' means: "the caller tells callee: you should use the size which I
give you, I am sure it is OK, do not care about whether it can cause
memory overflow or not".


The diff may like this:

--------------------------------diff begin------------------------------

diff --git a/mm/slub.c b/mm/slub.c
index 2b02d66..8564677 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3988,12 +3988,12 @@ static void free_loc_track(struct loc_track *t)
 			get_order(sizeof(struct location) * t->max));
 }
 
-static int alloc_loc_track(struct loc_track *t, unsigned long max, gfp_t flags)
+static int alloc_loc_track(struct loc_track *t, unsigned long size, gfp_t flags)
 {
 	struct location *l;
 	int order;
 
-	order = get_order(sizeof(struct location) * max);
+	order = get_order(sizeof(struct location) * size);
 
 	l = (void *)__get_free_pages(flags, order);
 	if (!l)
@@ -4003,7 +4003,7 @@ static int alloc_loc_track(struct loc_track *t, unsigned long max, gfp_t flags)
 		memcpy(l, t->loc, sizeof(struct location) * t->count);
 		free_loc_track(t);
 	}
-	t->max = max;
+	t->max = size;
 	t->loc = l;
 	return 1;
 }

--------------------------------diff end--------------------------------

Thanks
-- 
Chen Gang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-07-19  0:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08  8:07 [PATCH] mm/slub.c: remove 'per_cpu' which is useless variable Chen Gang
2013-07-11  6:45 ` Pekka Enberg
2013-07-11  6:50   ` Chen Gang
2013-07-11 16:45     ` Christoph Lameter
2013-07-11 18:28       ` Pekka Enberg
2013-07-11 20:16         ` Christoph Lameter
2013-07-11 23:52           ` Chen Gang
2013-07-12  0:23             ` [PATCH v2] " Chen Gang
2013-07-12  0:55               ` [PATCH] mm/slub.c: add parameter length checking for alloc_loc_track() Chen Gang
2013-07-12 13:49                 ` Christoph Lameter
2013-07-15  0:17                   ` Chen Gang
2013-07-15 15:16                     ` Christoph Lameter
2013-07-16  1:03                       ` Chen Gang
2013-07-17 15:03                         ` Christoph Lameter
2013-07-18  0:43                           ` Chen Gang
2013-07-18 13:45                             ` Christoph Lameter
2013-07-19  0:05                               ` Chen Gang F T [this message]
2013-07-19 13:57                                 ` Christoph Lameter
2013-07-22  0:27                                   ` Chen Gang
2013-07-22  0:42                                   ` Wanpeng Li
2013-07-22  0:42                                   ` Wanpeng Li
2013-07-22  1:30                                     ` Chen Gang
2013-07-12 13:45               ` [PATCH v2] mm/slub.c: remove 'per_cpu' which is useless variable Christoph Lameter
2013-07-15  0:08                 ` Chen Gang

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=51E882E1.4000504@gmail.com \
    --to=chen.gang.flying.transformer@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=gang.chen@asianux.com \
    --cc=linux-mm@kvack.org \
    --cc=mpm@selenic.com \
    --cc=penberg@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 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.