From: Laura Garcia <nevola@gmail.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH] staging: netlogic: Return zero pointer after failed kmalloc
Date: Wed, 24 Feb 2016 17:47:17 +0100 [thread overview]
Message-ID: <20160224164715.GA3058@sonyv> (raw)
In-Reply-To: <alpine.DEB.2.02.1602241020130.2149@localhost6.localdomain6>
On Wed, Feb 24, 2016 at 10:23:09AM +0100, Julia Lawall wrote:
>
>
> On Tue, 23 Feb 2016, Laura Garcia wrote:
>
> > On Tue, Feb 23, 2016 at 09:42:04PM +0100, Julia Lawall wrote:
> > >
> > >
> > > On Thu, 18 Feb 2016, Laura Garcia Liebana wrote:
> > >
> > > > Return a ZERO_SIZE_PTR in the xlr_config_spill function if the
> > > > kmalloc returns an invalid value. This change prevents a possible
> > > > segmentation fault as the invalid pointer is fed into PTR_ALIGN macro.
> > > >
> > > > Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
> > > > ---
> > > > drivers/staging/netlogic/xlr_net.c | 4 +++-
> > > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/staging/netlogic/xlr_net.c b/drivers/staging/netlogic/xlr_net.c
> > > > index 98e74d7..0015847 100644
> > > > --- a/drivers/staging/netlogic/xlr_net.c
> > > > +++ b/drivers/staging/netlogic/xlr_net.c
> > > > @@ -437,8 +437,10 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
> > > > base = priv->base_addr;
> > > > spill_size = size;
> > > > spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
> > > > - if (!spill)
> > > > + if (!spill) {
> > > > pr_err("Unable to allocate memory for spill area!\n");
> > > > + return ZERO_SIZE_PTR;
> > >
> > > Why did you choose this as the return value, rather than NULL? Is there a
> > > way that the first argument to kmalloc can be 0? Also, the containing
> > > function, xlr_config_spill, is called in a number of places where the
> > > results is stored in a structure field with no error checking. Have you
> > > traced through the code to see if it is appropriate to store and invalid
> > > pointer in these fields? At the moment, the crash will at least happen
> > > near the location of the faulty assignment. It could get harder to debug,
> > > if the bad value will propagate through structure fields to other parts of
> > > the driver.
> > >
> > > julia
> > >
> > > > + }
> > > >
> > > > spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
> > > > phys_addr = virt_to_phys(spill);
> > > > --
> > > > 2.7.0
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > > > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > > > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > > > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160218173839.GA9157%40sonyv.
> > > > For more options, visit https://groups.google.com/d/optout.
> > > >
>
> > I guessed that it was the best way to return an invalid pointer after a
> > kmalloc. Doesn't seem that the structure where the function return is
> > stored is called anymore. So I believe that returning a NULL will be
> > safe in this case.
>
> I'm not sure to understand the second sentence. Is the kmalloc useless?
> To my recollection, the result of the function is stored in several
> structure fields. Are these structure fields never used?
>
Exactly, these structure fields seem that are never used.
> Also, when you reply to a comment, could you put your reply just under the
> comment, with blank lines around it? Otherwise, the reply is hard to
> find.
>
Ok, got it.
thanks.
> thanks,
> julia
>
next prev parent reply other threads:[~2016-02-24 16:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-18 17:38 [PATCH] staging: netlogic: Return zero pointer after failed kmalloc Laura Garcia Liebana
2016-02-23 20:42 ` [Outreachy kernel] " Julia Lawall
2016-02-23 22:36 ` Laura Garcia
2016-02-24 9:23 ` Julia Lawall
2016-02-24 16:47 ` Laura Garcia [this message]
2016-02-24 16:55 ` Julia Lawall
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=20160224164715.GA3058@sonyv \
--to=nevola@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=outreachy-kernel@googlegroups.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.