LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Andrew Morton <akpm@osdl.org>, Ingo Molnar <mingo@elte.hu>,
tglx@linutronix.de, linux-kernel@vger.kernel.org,
selinux@tycho.nsa.gov, jmorris@namei.org
Subject: Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.
Date: Wed, 07 Feb 2007 16:12:18 -0500 [thread overview]
Message-ID: <1170882738.11912.144.camel@moss-spartans.epoch.ncsc.mil> (raw)
In-Reply-To: <1170872654.11912.87.camel@moss-spartans.epoch.ncsc.mil>
On Wed, 2007-02-07 at 13:24 -0500, Stephen Smalley wrote:
> On Tue, 2007-02-06 at 14:21 -0700, Eric W. Biederman wrote:
> > This time instead of generating the generating the paths from proc_dir_entries
> > generate the labels from the names in the sysctl ctl_tables themselves. This
> > removes an unnecessary layer of indirection, allows this to work even when
> > procfs support is not compiled into the kernel, and especially allows it
> > to work now that ctl_tables no longer have a proc_dir_entry field.
>
> Thanks, looks sane.
>
> > I continue passing "proc" into genfs sid although that is complete nonsense
> > to allow existing selinux policies to work without modification.
> >
> > Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
>
> Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Hmmm...but in testing the patch, I don't seem to (consistently) reach
these checks when accessing via /proc/sys. I see that you are caching
the mode information and using it in some cases rather than calling the
sysctl_perm function.
One related but separate issue is that the /proc/sys inode labeling is
also affected by the sysctl patch series. Those inodes used to be
labeled by selinux_proc_get_sid (from selinux_d_instantiate), but that
no longer works, so they now fall back to the superblock SID (generic
proc label). That changes the inode permission checks on an attempt to
access a /proc/sys node and will likely cause denials under current
policy for confined domains since one wouldn't generally be writing to
the generic proc label. If you always called sysctl_perm from the proc
sysctl code, we could possibly dispense with inode permission checking
on those inodes, e.g. marking them private.
>
> > ---
> > security/selinux/hooks.c | 43 +++++++++++++++++++++++++++++++++++++++++--
> > 1 files changed, 41 insertions(+), 2 deletions(-)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 3a36057..c17a8dd 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -1424,6 +1424,41 @@ static int selinux_capable(struct task_struct *tsk, int cap)
> > return task_has_capability(tsk,cap);
> > }
> >
> > +static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
> > +{
> > + int buflen, rc;
> > + char *buffer, *path, *end;
> > +
> > + rc = -ENOMEM;
> > + buffer = (char*)__get_free_page(GFP_KERNEL);
> > + if (!buffer)
> > + goto out;
> > +
> > + buflen = PAGE_SIZE;
> > + end = buffer+buflen;
> > + *--end = '\0';
> > + buflen--;
> > + path = end-1;
> > + *path = '/';
> > + while (table) {
> > + const char *name = table->procname;
> > + size_t namelen = strlen(name);
> > + buflen -= namelen + 1;
> > + if (buflen < 0)
> > + goto out_free;
> > + end -= namelen;
> > + memcpy(end, name, namelen);
> > + *--end = '/';
> > + path = end;
> > + table = table->parent;
> > + }
> > + rc = security_genfs_sid("proc", path, tclass, sid);
> > +out_free:
> > + free_page((unsigned long)buffer);
> > +out:
> > + return rc;
> > +}
> > +
> > static int selinux_sysctl(ctl_table *table, int op)
> > {
> > int error = 0;
> > @@ -1438,8 +1473,12 @@ static int selinux_sysctl(ctl_table *table, int op)
> >
> > tsec = current->security;
> >
> > - /* Use the well-defined sysctl SID. */
> > - tsid = SECINITSID_SYSCTL;
> > + rc = selinux_sysctl_get_sid(table, (op == 0001) ?
> > + SECCLASS_DIR : SECCLASS_FILE, &tsid);
> > + if (rc) {
> > + /* Default to the well-defined sysctl SID. */
> > + tsid = SECINITSID_SYSCTL;
> > + }
> >
> > /* The op values are "defined" in sysctl.c, thereby creating
> > * a bad coupling between this module and sysctl.c */
--
Stephen Smalley
National Security Agency
next prev parent reply other threads:[~2007-02-07 21:17 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200701280106.l0S16CG3019873@shell0.pdx.osdl.net>
[not found] ` <20070127172410.2b041952.akpm@osdl.org>
[not found] ` <1169972718.17469.164.camel@localhost.localdomain>
[not found] ` <20070128003549.2ca38dc8.akpm@osdl.org>
[not found] ` <20070128093358.GA2071@elte.hu>
[not found] ` <20070128095712.GA6485@elte.hu>
[not found] ` <20070128100627.GA8416@elte.hu>
[not found] ` <20070128104548.a835d859.akpm@osdl.org>
2007-01-28 19:21 ` [PATCH] sysctl selinux: Don't look at table->de Eric W. Biederman
2007-01-29 13:04 ` Stephen Smalley
2007-01-29 15:23 ` James Morris
2007-01-29 17:55 ` Eric W. Biederman
2007-01-29 19:26 ` Stephen Smalley
2007-01-29 17:43 ` Eric W. Biederman
2007-01-29 18:43 ` Stephen Smalley
2007-01-29 19:08 ` Casey Schaufler
2007-01-29 20:07 ` Stephen Smalley
2007-01-30 10:25 ` Christoph Hellwig
2007-01-30 17:19 ` Casey Schaufler
2007-01-29 19:16 ` Eric W. Biederman
2007-01-29 23:28 ` Russell Coker
2007-02-06 21:16 ` [PATCH 1/2] sysctl: Add a parent entry to ctl_table and set the parent entry Eric W. Biederman
2007-02-06 21:21 ` [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls Eric W. Biederman
2007-02-07 18:24 ` Stephen Smalley
2007-02-07 21:12 ` Stephen Smalley [this message]
2007-02-07 21:54 ` Stephen Smalley
2007-02-07 22:21 ` Eric W. Biederman
2007-02-08 15:07 ` Stephen Smalley
2007-02-08 1:57 ` Eric W. Biederman
2007-02-08 15:01 ` Stephen Smalley
2007-02-08 17:53 ` Eric W. Biederman
2007-02-08 18:13 ` Stephen Smalley
2007-02-08 22:17 ` Eric W. Biederman
2007-02-08 22:51 ` [PATCH 0/5] sysctl cleanup selinux fixes Eric W. Biederman
2007-02-08 22:53 ` [PATCH 1/5] sysctl: Remove declaration of nonexistent sysctl_init() Eric W. Biederman
2007-02-08 22:54 ` [PATCH 2/5] sysctl: Set the parent field in the root sysctl table Eric W. Biederman
2007-02-08 22:55 ` [PATCH 3/5] sysctl: Fix the selinux_sysctl_get_sid Eric W. Biederman
2007-02-08 23:02 ` [PATCH 4/5] selinux: Enhance selinux to always ignore private inodes Eric W. Biederman
2007-02-08 23:04 ` [PATCH 5/5] sysctl: Hide the sysctl proc inodes from selinux Eric W. Biederman
2007-02-09 12:26 ` [PATCH 4/5] selinux: Enhance selinux to always ignore private inodes Stephen Smalley
2007-02-09 12:24 ` [PATCH 3/5] sysctl: Fix the selinux_sysctl_get_sid Stephen Smalley
2007-02-09 11:05 ` [PATCH 0/5] sysctl cleanup selinux fixes Andrew Morton
2007-02-09 18:09 ` Eric W. Biederman
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=1170882738.11912.144.camel@moss-spartans.epoch.ncsc.mil \
--to=sds@tycho.nsa.gov \
--cc=akpm@osdl.org \
--cc=ebiederm@xmission.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=selinux@tycho.nsa.gov \
--cc=tglx@linutronix.de \
--subject='Re: [PATCH 2/2] sysctl: Restore the selinux path based label lookup for sysctls.' \
/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
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).