From: "Serge E. Hallyn" <serge@hallyn.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>,
Gergely Nagy <algernon@balabit.hu>,
david@lang.hm, Alan Cox <alan@lxorguk.ukuu.org.uk>,
Marc Koschewski <marc@osknowledge.org>,
lkml <linux-kernel@vger.kernel.org>,
James Morris <jmorris@namei.org>,
Nick Bowler <nbowler@elliptictech.com>
Subject: Re: [PATCH 1/1] cap_syslog: don't refuse cap_sys_admin for now (v3)
Date: Thu, 10 Feb 2011 22:43:01 +0000 [thread overview]
Message-ID: <20110210224301.GA26562@mail.hallyn.com> (raw)
In-Reply-To: <AANLkTin-2uDkjPuSPmUE_HZdpxk9zd=Qop=nf==jsyLA@mail.gmail.com>
Quoting Linus Torvalds (torvalds@linux-foundation.org):
> On Thu, Feb 10, 2011 at 6:40 AM, Serge E. Hallyn <serge@hallyn.com> wrote:
> >
> > Please apply.
>
> Hmm. So I detest the duplication and the ugly resulting code. It was
> a bit hard to follow before, now it's just nasty.
>
> Why not make this all into some nicer helper functions instead -
> something simple like the attached?
>
> UNTESTED! I'm not going to apply it unless I get acks/tested-by's.
>
> Linus
It looks correct (and much nicer indeed)
Acked-by: Serge Hallyn <serge@hallyn.com>
Setting up a box to actually test on...
thanks,
-serge
> kernel/printk.c | 54 +++++++++++++++++++++++++++++++++++-------------------
> 1 files changed, 35 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/printk.c b/kernel/printk.c
> index 2ddbdc7..f51214c 100644
> --- a/kernel/printk.c
> +++ b/kernel/printk.c
> @@ -262,25 +262,47 @@ int dmesg_restrict = 1;
> int dmesg_restrict;
> #endif
>
> +static int syslog_action_restricted(int type)
> +{
> + if (dmesg_restrict)
> + return 1;
> + /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
> + return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
> +}
> +
> +static int check_syslog_permissions(int type, bool from_file)
> +{
> + /*
> + * If this is from /proc/kmsg and we've already opened it, then we've
> + * already the capabilities checks at open time.
> + */
> + if (from_file && type != SYSLOG_ACTION_OPEN)
> + return 0;
> +
> + if (syslog_action_restricted(type)) {
> + if (capable(CAP_SYSLOG))
> + return 0;
> + /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
> + if (capable(CAP_SYS_ADMIN)) {
> + WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
> + "but no CAP_SYSLOG (deprecated).\n");
> + return 0;
> + }
> + return -EPERM;
> + }
> + return 0;
> +}
> +
> int do_syslog(int type, char __user *buf, int len, bool from_file)
> {
> unsigned i, j, limit, count;
> int do_clear = 0;
> char c;
> - int error = 0;
> + int error;
>
> - /*
> - * If this is from /proc/kmsg we only do the capabilities checks
> - * at open time.
> - */
> - if (type == SYSLOG_ACTION_OPEN || !from_file) {
> - if (dmesg_restrict && !capable(CAP_SYSLOG))
> - goto warn; /* switch to return -EPERM after 2.6.39 */
> - if ((type != SYSLOG_ACTION_READ_ALL &&
> - type != SYSLOG_ACTION_SIZE_BUFFER) &&
> - !capable(CAP_SYSLOG))
> - goto warn; /* switch to return -EPERM after 2.6.39 */
> - }
> + error = check_syslog_permissions(type, from_file);
> + if (error)
> + goto out;
>
> error = security_syslog(type);
> if (error)
> @@ -423,12 +445,6 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
> }
> out:
> return error;
> -warn:
> - /* remove after 2.6.39 */
> - if (capable(CAP_SYS_ADMIN))
> - WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
> - "but no CAP_SYSLOG (deprecated and denied).\n");
> - return -EPERM;
> }
>
> SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
next prev parent reply other threads:[~2011-02-10 22:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-10 14:40 [PATCH 1/1] cap_syslog: don't refuse cap_sys_admin for now (v3) Serge E. Hallyn
2011-02-10 19:16 ` Linus Torvalds
2011-02-10 22:43 ` Serge E. Hallyn [this message]
2011-02-10 22:59 ` James Morris
2011-02-11 16:32 ` Serge E. Hallyn
2011-08-03 16:48 ` [PATCH/RFC] cap_syslog: make CAP_SYS_ADMIN deprecation notice less alarming Jonathan Nieder
2011-08-04 1:28 ` James Morris
2011-08-04 4:39 ` Serge E. Hallyn
2011-08-05 13:45 ` James Morris
2011-08-05 18:50 ` Linus Torvalds
2011-08-08 4:22 ` [PATCH v2] cap_syslog: don't use WARN_ONCE for CAP_SYS_ADMIN deprecation warning Jonathan Nieder
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=20110210224301.GA26562@mail.hallyn.com \
--to=serge@hallyn.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=algernon@balabit.hu \
--cc=david@lang.hm \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc@osknowledge.org \
--cc=nbowler@elliptictech.com \
--cc=torvalds@linux-foundation.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).