All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Randy.Dunlap" <rddunlap@osdl.org>
To: Yum Rayan <yum.rayan@gmail.com>
Cc: linux-kernel@vger.kernel.org, rusty@rustcorp.com.au
Subject: Re: [PATCH] Reduce stack usage in module.c
Date: Wed, 30 Mar 2005 10:01:04 -0800	[thread overview]
Message-ID: <424AE960.8020906@osdl.org> (raw)
In-Reply-To: <df35dfeb050329222132823897@mail.gmail.com>

Yum Rayan wrote:
> On Tue, 29 Mar 2005 09:43:12 -0800, Randy.Dunlap <rddunlap@osdl.org> wrote:
> 
>>Yum Rayan wrote:
>>
>>>Attempt to reduce stack usage in module.c (linux-2.6.12-rc1-mm3).
>>>Specifically from checkstack.pl
> 
>>>Also while at it, fix following in who_is_doing_it(...)
>>>- use only as much memory is needed
>>>- do not write past array index for the boundary case
>>
>>I don't see a boundary case problem with the current code,
>>hence I don't see why the kmalloc(len + 1, GFP_KERNEL) is
>>needed...
> 
> 
> Let's consider the original code and len = 513
> 
>    1399 static void who_is_doing_it(void)
>    1400 {
>    1401         /* Print out all the args. */
>    1402         char args[512];
>    1403         unsigned long i, len = current->mm->arg_end -
> current->mm->arg_start;
>    1404
>    1405         if (len > 512)
>    1406                 len = 512;
>    1407
>    1408         len -= copy_from_user(args, (void
> *)current->mm->arg_start, len);
>    1409
>    1410         for (i = 0; i < len; i++) {
>    1411                 if (args[i] == '\0')
>    1412                         args[i] = ' ';
>    1413         }
>    1414         args[i] = 0;
>    1415         printk("ARGS: %s\n", args);
>    1416 }
> 
> After lines 1410 thru 1413, "i" wil be 512. So line 1414 will be
> "args[512] = 0". But args is 512 byte array with last legally
> accessible element at 511?

Yes, it's so obvious (now).  :)

>>File names start one level deeper than wanted.  They should begin
>>with linux/ or a/ or ./ e.g.
>>There are plenty of docs on this, please let me know if you need
>>references to them.
> 
> 
> Point noted. Will post patch to linux/Documentation/SubmittingPatches,
> hopefully making it more clear. Reworked patch at end of email.

Good idea, thanks.

-- 
~Randy

  reply	other threads:[~2005-03-30 18:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-29  7:13 [PATCH] Reduce stack usage in module.c Yum Rayan
2005-03-29 17:43 ` Randy.Dunlap
2005-03-30  6:21   ` Yum Rayan
2005-03-30 18:01     ` Randy.Dunlap [this message]
2005-03-30 19:44       ` Jesper Juhl

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=424AE960.8020906@osdl.org \
    --to=rddunlap@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=yum.rayan@gmail.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.