* [PATCH] selinux: check for failed kmalloc in security_sid_to_context
@ 2006-04-27 2:07 Serge E. Hallyn
2006-04-27 3:25 ` James Morris
0 siblings, 1 reply; 4+ messages in thread
From: Serge E. Hallyn @ 2006-04-27 2:07 UTC (permalink / raw)
To: lkml, Stephen Smalley, James Morris
Check for NULL kmalloc return value before writing to it.
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
security/selinux/ss/services.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
3d9cf05c7fa2578f87648dd0862e70cf7959ad7a
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 6149248..20b1065 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
*scontext_len = strlen(initial_sid_to_string[sid]) + 1;
scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
+ if (!scontextp) {
+ rc = -ENOMEM;
+ goto out;
+ }
strcpy(scontextp, initial_sid_to_string[sid]);
*scontext = scontextp;
goto out;
--
1.3.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selinux: check for failed kmalloc in security_sid_to_context
2006-04-27 2:07 [PATCH] selinux: check for failed kmalloc in security_sid_to_context Serge E. Hallyn
@ 2006-04-27 3:25 ` James Morris
2006-05-08 17:46 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: James Morris @ 2006-04-27 3:25 UTC (permalink / raw)
To: Serge E. Hallyn; +Cc: lkml, Stephen Smalley, James Morris
On Wed, 26 Apr 2006, Serge E. Hallyn wrote:
> Check for NULL kmalloc return value before writing to it.
>
> Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Acked-by: James Morris <jmorris@namei.org>
> ---
>
> security/selinux/ss/services.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> 3d9cf05c7fa2578f87648dd0862e70cf7959ad7a
> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index 6149248..20b1065 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
>
> *scontext_len = strlen(initial_sid_to_string[sid]) + 1;
> scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
> + if (!scontextp) {
> + rc = -ENOMEM;
> + goto out;
> + }
> strcpy(scontextp, initial_sid_to_string[sid]);
> *scontext = scontextp;
> goto out;
>
--
James Morris
<jmorris@namei.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selinux: check for failed kmalloc in security_sid_to_context
2006-04-27 3:25 ` James Morris
@ 2006-05-08 17:46 ` Andrew Morton
2006-05-08 18:21 ` Stephen Smalley
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2006-05-08 17:46 UTC (permalink / raw)
To: James Morris; +Cc: serue, linux-kernel, sds, jmorris
James Morris <jmorris@namei.org> wrote:
>
> On Wed, 26 Apr 2006, Serge E. Hallyn wrote:
>
> > Check for NULL kmalloc return value before writing to it.
> >
> > Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
>
> Acked-by: James Morris <jmorris@namei.org>
>
>
> > ---
> >
> > security/selinux/ss/services.c | 4 ++++
> > 1 files changed, 4 insertions(+), 0 deletions(-)
> >
> > 3d9cf05c7fa2578f87648dd0862e70cf7959ad7a
> > diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> > index 6149248..20b1065 100644
> > --- a/security/selinux/ss/services.c
> > +++ b/security/selinux/ss/services.c
> > @@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
> >
> > *scontext_len = strlen(initial_sid_to_string[sid]) + 1;
> > scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
> > + if (!scontextp) {
> > + rc = -ENOMEM;
> > + goto out;
> > + }
> > strcpy(scontextp, initial_sid_to_string[sid]);
> > *scontext = scontextp;
> > goto out;
> >
>
Given that GFP_ATOMIC can fail and it'll cause an oops I'll queue this for
2.6.17 and shall send it in the direction of the -stable guys too, thanks.
What will happen when one of the GFP_ATOMIC allocations in there fails?
Will the computer become insecure?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selinux: check for failed kmalloc in security_sid_to_context
2006-05-08 17:46 ` Andrew Morton
@ 2006-05-08 18:21 ` Stephen Smalley
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Smalley @ 2006-05-08 18:21 UTC (permalink / raw)
To: Andrew Morton; +Cc: James Morris, serue, linux-kernel, jmorris
On Mon, 2006-05-08 at 10:46 -0700, Andrew Morton wrote:
> James Morris <jmorris@namei.org> wrote:
> >
> > On Wed, 26 Apr 2006, Serge E. Hallyn wrote:
> >
> > > Check for NULL kmalloc return value before writing to it.
> > >
> > > Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
> >
> > Acked-by: James Morris <jmorris@namei.org>
> >
> >
> > > ---
> > >
> > > security/selinux/ss/services.c | 4 ++++
> > > 1 files changed, 4 insertions(+), 0 deletions(-)
> > >
> > > 3d9cf05c7fa2578f87648dd0862e70cf7959ad7a
> > > diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> > > index 6149248..20b1065 100644
> > > --- a/security/selinux/ss/services.c
> > > +++ b/security/selinux/ss/services.c
> > > @@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
> > >
> > > *scontext_len = strlen(initial_sid_to_string[sid]) + 1;
> > > scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
> > > + if (!scontextp) {
> > > + rc = -ENOMEM;
> > > + goto out;
> > > + }
> > > strcpy(scontextp, initial_sid_to_string[sid]);
> > > *scontext = scontextp;
> > > goto out;
> > >
> >
>
> Given that GFP_ATOMIC can fail and it'll cause an oops I'll queue this for
> 2.6.17 and shall send it in the direction of the -stable guys too, thanks.
Note however that this can only occur prior to initial policy load
by /sbin/init; after that, we don't follow that branch.
> What will happen when one of the GFP_ATOMIC allocations in there fails?
> Will the computer become insecure?
No, it doesn't affect the access control enforcement. The caller just
can't get the context string in that case, so in the case of the AVC or
audit, it falls back to only logging the SID for later analysis. The
audit people are interested in having a way to dump the kernel's SID
table in that case, so we may end up exporting that via selinuxfs. In
some other cases where we are returning the context to userspace, the
program would get the ENOMEM error ultimately and have to retry when
memory was available.
--
Stephen Smalley
National Security Agency
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-05-08 18:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-27 2:07 [PATCH] selinux: check for failed kmalloc in security_sid_to_context Serge E. Hallyn
2006-04-27 3:25 ` James Morris
2006-05-08 17:46 ` Andrew Morton
2006-05-08 18:21 ` Stephen Smalley
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®