* null pointer questions
@ 2001-11-02 7:30 Ken Ashcraft
2001-11-02 12:51 ` Roman Zippel
0 siblings, 1 reply; 7+ messages in thread
From: Ken Ashcraft @ 2001-11-02 7:30 UTC (permalink / raw)
To: linux-kernel; +Cc: engler
Two questions:
1. If I pass size 0 to kmalloc, what does it return?
2. What happens if I pass a null pointer as the destination parameter
to copy_from_user? Does copy_from_user handle it safely or will the
kernel seg fault?
Thanks for your answers,
Ken Ashcraft
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 7:30 null pointer questions Ken Ashcraft
@ 2001-11-02 12:51 ` Roman Zippel
2001-11-02 13:16 ` lkml user
2001-11-02 22:42 ` Ken Ashcraft
0 siblings, 2 replies; 7+ messages in thread
From: Roman Zippel @ 2001-11-02 12:51 UTC (permalink / raw)
To: Ken Ashcraft; +Cc: linux-kernel, engler
Hi,
On Thu, 1 Nov 2001, Ken Ashcraft wrote:
> 1. If I pass size 0 to kmalloc, what does it return?
AFAIK size is always rounded up, so you get the smallest possible
allocation unit.
> 2. What happens if I pass a null pointer as the destination parameter
> to copy_from_user? Does copy_from_user handle it safely or will the
> kernel seg fault?
The kernel won't crash, but it might fail (depending on whether 0 is a
valid user space address or not).
bye, Roman
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 12:51 ` Roman Zippel
@ 2001-11-02 13:16 ` lkml user
2001-11-02 22:42 ` Ken Ashcraft
1 sibling, 0 replies; 7+ messages in thread
From: lkml user @ 2001-11-02 13:16 UTC (permalink / raw)
To: Roman Zippel; +Cc: linux-kernel, engler
On Fri, 2 Nov 2001, Roman Zippel wrote:
> Hi,
>
> On Thu, 1 Nov 2001, Ken Ashcraft wrote:
>
> > 1. If I pass size 0 to kmalloc, what does it return?
>
> AFAIK size is always rounded up, so you get the smallest possible
> allocation unit.
>
> > 2. What happens if I pass a null pointer as the destination parameter
> > to copy_from_user? Does copy_from_user handle it safely or will the
> > kernel seg fault?
>
> The kernel won't crash, but it might fail (depending on whether 0 is a
> valid user space address or not).
>
> bye, Roman
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 12:51 ` Roman Zippel
2001-11-02 13:16 ` lkml user
@ 2001-11-02 22:42 ` Ken Ashcraft
2001-11-02 23:20 ` Roman Zippel
2001-11-02 23:37 ` Brian Gerst
1 sibling, 2 replies; 7+ messages in thread
From: Ken Ashcraft @ 2001-11-02 22:42 UTC (permalink / raw)
To: Roman Zippel; +Cc: linux-kernel, engler
> > 2. What happens if I pass a null pointer as the destination parameter
> > to copy_from_user? Does copy_from_user handle it safely or will the
> > kernel seg fault?
>
> The kernel won't crash, but it might fail (depending on whether 0 is a
> valid user space address or not).
Why does it matter if 0 is a valid user space or not? If I make the call
copy_from_user(0, user_ptr, 4);
the null pointer is the kernel address, not the user address. Can you
clarify please?
Thanks
Ken
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 22:42 ` Ken Ashcraft
@ 2001-11-02 23:20 ` Roman Zippel
2001-11-02 23:37 ` Brian Gerst
1 sibling, 0 replies; 7+ messages in thread
From: Roman Zippel @ 2001-11-02 23:20 UTC (permalink / raw)
To: Ken Ashcraft; +Cc: linux-kernel, engler
Hi,
Ken Ashcraft wrote:
> Why does it matter if 0 is a valid user space or not? If I make the call
>
> copy_from_user(0, user_ptr, 4);
>
> the null pointer is the kernel address, not the user address. Can you
> clarify please?
Sorry, I misunderstood you. The kernel address has to be a valid address
of course, otherwise the behavior is undefined.
bye, Roman
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 22:42 ` Ken Ashcraft
2001-11-02 23:20 ` Roman Zippel
@ 2001-11-02 23:37 ` Brian Gerst
2001-11-02 23:39 ` Brian Gerst
1 sibling, 1 reply; 7+ messages in thread
From: Brian Gerst @ 2001-11-02 23:37 UTC (permalink / raw)
To: Ken Ashcraft; +Cc: linux-kernel
Ken Ashcraft wrote:
>
> > > 2. What happens if I pass a null pointer as the destination parameter
> > > to copy_from_user? Does copy_from_user handle it safely or will the
> > > kernel seg fault?
> >
> > The kernel won't crash, but it might fail (depending on whether 0 is a
> > valid user space address or not).
>
> Why does it matter if 0 is a valid user space or not? If I make the call
>
> copy_from_user(0, user_ptr, 4);
>
> the null pointer is the kernel address, not the user address. Can you
> clarify please?
copy_from_user uses the string move instruction on the x86, so the
exception code would assume the source faulted not the dest. It would
return -EFAULT instead of causing an oops.
--
Brian Gerst
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: null pointer questions
2001-11-02 23:37 ` Brian Gerst
@ 2001-11-02 23:39 ` Brian Gerst
0 siblings, 0 replies; 7+ messages in thread
From: Brian Gerst @ 2001-11-02 23:39 UTC (permalink / raw)
To: Ken Ashcraft; +Cc: linux-kernel
Brian Gerst wrote:
>
> Ken Ashcraft wrote:
> >
> > > > 2. What happens if I pass a null pointer as the destination parameter
> > > > to copy_from_user? Does copy_from_user handle it safely or will the
> > > > kernel seg fault?
> > >
> > > The kernel won't crash, but it might fail (depending on whether 0 is a
> > > valid user space address or not).
> >
> > Why does it matter if 0 is a valid user space or not? If I make the call
> >
> > copy_from_user(0, user_ptr, 4);
> >
> > the null pointer is the kernel address, not the user address. Can you
> > clarify please?
>
> copy_from_user uses the string move instruction on the x86, so the
> exception code would assume the source faulted not the dest. It would
> return -EFAULT instead of causing an oops.
Err, would return non-zero instead of -EFAULT.
--
Brian Gerst
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-11-02 23:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-02 7:30 null pointer questions Ken Ashcraft
2001-11-02 12:51 ` Roman Zippel
2001-11-02 13:16 ` lkml user
2001-11-02 22:42 ` Ken Ashcraft
2001-11-02 23:20 ` Roman Zippel
2001-11-02 23:37 ` Brian Gerst
2001-11-02 23:39 ` Brian Gerst
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).