Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH 5/5] security/selinux/ss: correct size computation

0 views
Skip to first unread message

Julia Lawall

unread,
Dec 6, 2009, 4:20:02 AM12/6/09
to
From: Julia Lawall <ju...@diku.dk>

The size argument to kcalloc should be the size of desired structure,
not the pointer to it.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@expression@
expression *x;
@@

x =
<+...
-sizeof(x)
+sizeof(*x)
...+>// </smpl>

Signed-off-by: Julia Lawall <ju...@diku.dk>

---
security/selinux/ss/services.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/security/selinux/ss/services.c b/security/selinux/ss/services.c
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -2555,7 +2555,7 @@ int security_get_classes(char ***classes
read_lock(&policy_rwlock);

*nclasses = policydb.p_classes.nprim;
- *classes = kcalloc(*nclasses, sizeof(*classes), GFP_ATOMIC);
+ *classes = kcalloc(*nclasses, sizeof(**classes), GFP_ATOMIC);
if (!*classes)
goto out;

@@ -2602,7 +2602,7 @@ int security_get_permissions(char *class
}

*nperms = match->permissions.nprim;
- *perms = kcalloc(*nperms, sizeof(*perms), GFP_ATOMIC);
+ *perms = kcalloc(*nperms, sizeof(**perms), GFP_ATOMIC);
if (!*perms)
goto out;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Eric Paris

unread,
Dec 7, 2009, 10:10:02 AM12/7/09
to
On Sun, 2009-12-06 at 10:16 +0100, Julia Lawall wrote:
> From: Julia Lawall <ju...@diku.dk>
>
> The size argument to kcalloc should be the size of desired structure,
> not the pointer to it.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @expression@
> expression *x;
> @@
>
> x =
> <+...
> -sizeof(x)
> +sizeof(*x)
> ...+>// </smpl>
>
> Signed-off-by: Julia Lawall <ju...@diku.dk>

Acked-by: Eric Paris <epa...@redhat.com>

no real hurry, to get this in, the sizeof() is the same in either case,
but it should be fixed.

James Morris

unread,
Dec 7, 2009, 5:20:02 PM12/7/09
to
On Sun, 6 Dec 2009, Julia Lawall wrote:

> From: Julia Lawall <ju...@diku.dk>
>
> The size argument to kcalloc should be the size of desired structure,
> not the pointer to it.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @expression@
> expression *x;
> @@
>
> x =
> <+...
> -sizeof(x)
> +sizeof(*x)
> ...+>// </smpl>
>
> Signed-off-by: Julia Lawall <ju...@diku.dk>


Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next


--
James Morris
<jmo...@namei.org>

0 new messages