public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jiri Kosina <jkosina@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mateusz Guzik <mguzik@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>,
	Mel Gorman <mgorman@suse.de>, Kay Sievers <kay@vrfy.org>
Subject: Re: [RFC PATCH] cmdline: Hide "debug" from /proc/cmdline
Date: Tue, 15 Apr 2014 09:26:35 +0200	[thread overview]
Message-ID: <20140415072635.GA5984@pd.tnic> (raw)
In-Reply-To: <CA+55aFyphF8kd4OwWdar4p5M1=Sxc54sfk0RWFPpO6zrezZwJA@mail.gmail.com>

Hi Linus,

just checking on the status here: what did we decide on this one in
the end?

It works as expected, it is a good idea to have it as a protection
against every user space abuser, maybe we should apply it now that the
merge window is over and things are calming down?

Or should I remind you the next merge window?

Thanks.

On Wed, Apr 02, 2014 at 06:47:57PM -0700, Linus Torvalds wrote:
> On Wed, Apr 2, 2014 at 4:52 PM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > TOTALLY UNTESTED. But it really isn't complex.
> 
> Oh, and here's a patch that is actually lightly tested. I did
> 
>     while :; do echo hello; done > /dev/kmsg
> 
> (the 'yes' program buffers output, so won't work) and I get
> 
>     [  122.062912] hello
>     [  122.062915] hello
>     [  122.062918] hello
>     [  122.062921] hello
>     [  122.062924] hello
>     [  122.062927] hello
>     [  122.062930] hello
>     [  122.062932] hello
>     [  122.062935] hello
>     [  122.062938] hello
>     [  127.062671] bash: 2104439 callbacks suppressed
> 
> so it works (repeating every five seconds, as expected).
> 
> It's definitely not perfect - if we suppress output, and the process
> then closes the file descriptor rather than continuing to write more,
> you won't  get that "suppressed" message. But it's a usable starting
> point for testing and commentary on the actual limits.
> 
> So we should probably add reporting about suppressed messages at file
> close time, and we should tweak the limits (for example, perhaps not
> limit things if the buffers are largely empty - which happens at
> bootup), but on the whole I think this is a reasonable thing to do.
> 
> Whether it actually fixes the problem that Borislav had is
> questionable, of course. For all I know, systemd debug mode generates
> so much data in *other* ways and then causes feedback loops with the
> kernel debugging that this patch is totally immaterial, and dmesg was
> never the main issue. But unlike the "hide 'debug' from
> /proc/cmdline", I think this patch at least _conceptually_ makes a lot
> of sense, even if systemd gets fixed, so ...
> 
> Borislav?
> 
>                 Linus

>  kernel/printk/printk.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 4dae9cbe9259..b01ba10fb1b9 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -410,6 +410,7 @@ struct devkmsg_user {
>  	u64 seq;
>  	u32 idx;
>  	enum log_flags prev;
> +	struct ratelimit_state rs;
>  	struct mutex lock;
>  	char buf[8192];
>  };
> @@ -421,11 +422,15 @@ static ssize_t devkmsg_writev(struct kiocb *iocb, const struct iovec *iv,
>  	int i;
>  	int level = default_message_loglevel;
>  	int facility = 1;	/* LOG_USER */
> +	struct file *file = iocb->ki_filp;
> +	struct devkmsg_user *user = file->private_data;
>  	size_t len = iov_length(iv, count);
>  	ssize_t ret = len;
>  
> -	if (len > LOG_LINE_MAX)
> +	if (!user || len > LOG_LINE_MAX)
>  		return -EINVAL;
> +	if (!___ratelimit(&user->rs, current->comm))
> +		return ret;
>  	buf = kmalloc(len+1, GFP_KERNEL);
>  	if (buf == NULL)
>  		return -ENOMEM;
> @@ -656,21 +661,22 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
>  static int devkmsg_open(struct inode *inode, struct file *file)
>  {
>  	struct devkmsg_user *user;
> -	int err;
> -
> -	/* write-only does not need any file context */
> -	if ((file->f_flags & O_ACCMODE) == O_WRONLY)
> -		return 0;
>  
> -	err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
> -				       SYSLOG_FROM_READER);
> -	if (err)
> -		return err;
> +	/* write-only does not need to check read permissions */
> +	if ((file->f_flags & O_ACCMODE) != O_WRONLY) {
> +		int err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
> +					       SYSLOG_FROM_READER);
> +		if (err)
> +			return err;
> +	}
>  
>  	user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
>  	if (!user)
>  		return -ENOMEM;
>  
> +	/* Configurable? */
> +	ratelimit_state_init(&user->rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
> +
>  	mutex_init(&user->lock);
>  
>  	raw_spin_lock_irq(&logbuf_lock);


-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

  parent reply	other threads:[~2014-04-15  7:26 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-02 18:42 [RFC PATCH] cmdline: Hide "debug" from /proc/cmdline Steven Rostedt
2014-04-02 18:57 ` Linus Torvalds
2014-04-02 19:04 ` Andrew Morton
2014-04-02 19:05   ` Borislav Petkov
2014-04-02 19:08   ` Randy Dunlap
2014-04-02 19:50   ` Thomas Gleixner
2014-04-02 20:05     ` Richard Weinberger
2014-04-02 20:43       ` Thomas Gleixner
2014-04-02 22:18   ` Greg KH
2014-04-02 19:08 ` Borislav Petkov
2014-04-02 19:33   ` Steven Rostedt
2014-04-02 22:12 ` Mateusz Guzik
2014-04-02 22:30   ` David Daney
2014-04-02 22:37   ` Greg KH
2014-04-02 23:13   ` Linus Torvalds
2014-04-02 23:23     ` Jiri Kosina
2014-04-02 23:28       ` Andrew Morton
2014-04-02 23:42         ` Linus Torvalds
2014-04-02 23:47           ` Jiri Kosina
2014-04-02 23:52             ` Linus Torvalds
2014-04-02 23:57               ` Jiri Kosina
2014-04-03  1:38               ` Steven Rostedt
2014-04-03  1:47               ` Linus Torvalds
2014-04-03  9:03                 ` Borislav Petkov
2014-04-03 10:43                 ` Joerg Roedel
2014-04-03 17:05                   ` Theodore Ts'o
2014-04-03 17:09                     ` H. Peter Anvin
2014-04-03 17:18                       ` Theodore Ts'o
2014-04-03 19:19                         ` H. Peter Anvin
2014-04-04 18:21                     ` Andy Lutomirski
2014-04-04 18:32                       ` Linus Torvalds
2014-04-04 18:57                         ` Andy Lutomirski
2014-04-04 19:09                           ` Linus Torvalds
2014-04-04 21:17                         ` John Stoffel
2014-04-04 23:17                           ` Greg Kroah-Hartman
2014-04-05 14:37                             ` John Stoffel
2014-04-05 23:23                             ` Theodore Ts'o
2014-04-04 18:42                       ` Linus Torvalds
2014-04-04 18:51                         ` Andrew Morton
2014-04-04 18:57                           ` Linus Torvalds
2014-04-06 20:49                             ` David Timothy Strauss
2014-05-06  9:38                               ` Felipe Contreras
2014-04-04 19:44                           ` Steven Rostedt
2014-04-04 20:17                             ` Theodore Ts'o
2014-04-04 22:45                               ` Alexei Starovoitov
2014-04-04 22:48                                 ` Linus Torvalds
2014-04-04 19:00                         ` Andy Lutomirski
2014-04-03 11:23                 ` Borislav Petkov
2014-04-03 11:38                   ` Ingo Molnar
2014-04-15  7:26                 ` Borislav Petkov [this message]
2014-04-03 10:34               ` Måns Rullgård
2014-04-03 11:03                 ` Borislav Petkov
2014-04-06 17:19                   ` One Thousand Gnomes
2014-05-06  9:47                   ` Felipe Contreras
2014-04-02 23:47           ` Joe Perches
2014-04-02 23:31       ` Linus Torvalds
2014-04-03 11:25       ` Måns Rullgård
2014-04-03 15:17         ` Tim Bird
2014-04-03 18:06           ` Greg Kroah-Hartman
2014-05-06  9:35             ` Felipe Contreras
2014-04-07  4:54     ` Rusty Russell
2014-05-02 22:34       ` Andrew Morton
2014-05-05  2:17         ` Rusty Russell
2014-05-05 13:15           ` Randy Dunlap
2014-05-06  0:57             ` Rusty Russell
2014-05-19  8:06               ` Diego Viola
2014-05-19  8:11                 ` Diego Viola
2014-05-19 14:40                   ` Randy Dunlap
2014-05-20  1:26                     ` Rusty Russell
2014-05-20  6:26                       ` Diego Viola
2014-05-21  1:52                         ` Rusty Russell
2014-04-03  0:49   ` Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2014-04-23 15:15 Borislav Petkov
2014-04-23 20:44 ` Borislav Petkov

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=20140415072635.GA5984@pd.tnic \
    --to=bp@alien8.de \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jkosina@suse.cz \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mguzik@redhat.com \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --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