* [PATCH -v2] flex_arrays: allow zero length flex arrays
@ 2011-04-28 19:54 Eric Paris
2011-05-03 0:20 ` James Morris
0 siblings, 1 reply; 3+ messages in thread
From: Eric Paris @ 2011-04-28 19:54 UTC (permalink / raw)
To: dave
Cc: steffen.klassert, akpm, linux-kernel, linux-security-module,
selinux, sds
Just like kmalloc will allow one to allocate a 0 length segment of memory
flex arrays should do the same thing. It should bomb if you try to use
something, but it should at least allow the allocation.
This is needed because when SELinux switched to using flex_arrays in 2.6.38
the inability to allocate a 0 length array resulted in SELinux policy load
returning -ENOSPC when previously it worked.
Based-on-patch-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
Tested-by: Chris Richards <gizmo@giz-works.com>
Cc: stable@kernel.org [2.6.38+]
---
lib/flex_array.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 0c33b24..854b57b 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -253,9 +253,16 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
unsigned int end;
struct flex_array_part *part;
+ if (!start && !nr_elements)
+ return 0;
+ if (start >= fa->total_nr_elements)
+ return -ENOSPC;
+ if (!nr_elements)
+ return 0;
+
end = start + nr_elements - 1;
- if (start >= fa->total_nr_elements || end >= fa->total_nr_elements)
+ if (end >= fa->total_nr_elements)
return -ENOSPC;
if (elements_fit_in_base(fa))
return 0;
@@ -346,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
int part_nr;
int ret = 0;
+ if (!fa->total_nr_elements)
+ return 0;
if (elements_fit_in_base(fa))
return ret;
for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -v2] flex_arrays: allow zero length flex arrays
2011-04-28 19:54 [PATCH -v2] flex_arrays: allow zero length flex arrays Eric Paris
@ 2011-05-03 0:20 ` James Morris
2011-05-03 13:15 ` Eric Paris
0 siblings, 1 reply; 3+ messages in thread
From: James Morris @ 2011-05-03 0:20 UTC (permalink / raw)
To: Eric Paris
Cc: dave, steffen.klassert, akpm, linux-kernel,
linux-security-module, selinux, sds
On Thu, 28 Apr 2011, Eric Paris wrote:
> Just like kmalloc will allow one to allocate a 0 length segment of memory
> flex arrays should do the same thing. It should bomb if you try to use
> something, but it should at least allow the allocation.
This patch does not apply to current -linus.
--
James Morris
<jmorris@namei.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -v2] flex_arrays: allow zero length flex arrays
2011-05-03 0:20 ` James Morris
@ 2011-05-03 13:15 ` Eric Paris
0 siblings, 0 replies; 3+ messages in thread
From: Eric Paris @ 2011-05-03 13:15 UTC (permalink / raw)
To: James Morris
Cc: Eric Paris, dave, steffen.klassert, akpm, linux-kernel,
linux-security-module, selinux, sds
It builds on another patch already committed to my tree. I'll send
you a pull request for that branch right now!
-Eric
On Mon, May 2, 2011 at 8:20 PM, James Morris <jmorris@namei.org> wrote:
> On Thu, 28 Apr 2011, Eric Paris wrote:
>
>> Just like kmalloc will allow one to allocate a 0 length segment of memory
>> flex arrays should do the same thing. It should bomb if you try to use
>> something, but it should at least allow the allocation.
>
> This patch does not apply to current -linus.
>
> --
> James Morris
> <jmorris@namei.org>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-05-03 13:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-28 19:54 [PATCH -v2] flex_arrays: allow zero length flex arrays Eric Paris
2011-05-03 0:20 ` James Morris
2011-05-03 13:15 ` Eric Paris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®