[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1459336039.5907.37.camel@linux.intel.com>
Date: Wed, 30 Mar 2016 14:07:19 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Kees Cook <keescook@...omium.org>, James Morris <jmorris@...ei.org>
Cc: "Serge E. Hallyn" <serge@...lyn.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Kalle Valo <kvalo@...eaurora.org>,
Mauro Carvalho Chehab <mchehab@....samsung.com>,
Joe Perches <joe@...ches.com>,
Guenter Roeck <linux@...ck-us.net>,
Jiri Slaby <jslaby@...e.com>, Paul Moore <pmoore@...hat.com>,
Stephen Smalley <sds@...ho.nsa.gov>,
Mimi Zohar <zohar@...ux.vnet.ibm.com>,
Casey Schaufler <casey@...aufler-ca.com>,
Andreas Gruenbacher <agruenba@...hat.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Ulf Hansson <ulf.hansson@...aro.org>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
linux-security-module@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/5] string_helpers: add kstrdup_quotable_cmdline
On Mon, 2016-03-28 at 14:14 -0700, Kees Cook wrote:
> Provide an escaped (but readable: no inter-argument NULLs)
> commandline
> safe for logging.
> +/*
> + * Returns allocated NULL-terminated string containing process
> + * command line, with inter-argument NULLs replaced with spaces,
> + * and other special characters escaped.
> + */
> +char *kstrdup_quotable_cmdline(struct task_struct *task)
> +{
> + char *buffer, *quoted;
> + int i, res;
> +
> + buffer = kmalloc(PAGE_SIZE, GFP_TEMPORARY);
> + if (!buffer)
> + return NULL;
> +
> + res = get_cmdline(task, buffer, PAGE_SIZE - 1);
> + buffer[res] = '\0';
> +
> + /* Collapse trailing NULLs. */
> + for (; res > 0; res--)
> + if (buffer[res-1] != '\0')
> + break;
/* buffer[res] is '\0', so, predecrement is safe here */
while (buffer[--res] == '\0')
/* nothing */;
?
> +
> + /* Replace inter-argument NULLs. */
> + for (i = 0; i < res; i++)
> + if (buffer[i] == '\0')
> + buffer[i] = ' ';
> +
> + /* Make sure result is printable. */
> + quoted = kstrdup_quotable(buffer);
> + kfree(buffer);
> + return quoted;
> +}
> +EXPORT_SYMBOL_GPL(kstrdup_quotable_cmdline);
--
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Intel Finland Oy
Powered by blists - more mailing lists