LKML Archive on lore.kernel.org
 help / Atom feed
From: Paul Wise <pabs3@bonedaddy.net>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Cc: Jakub Wilk <jwilk@jwilk.net>
Subject: PROBLEM: Linux kernel.core_pattern with pipes does argument splitting after template expansion
Date: Tue, 19 Mar 2019 14:06:27 +0800
Message-ID: <c8b7ecb8508895bf4adb62a748e2ea2c71854597.camel@bonedaddy.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1611 bytes --]

The Linux kernel.core_pattern support for core dump handlers using the
pipe syntax does argument splitting after template expansion.

At minimum this bug could cause truncated values for the executable
name. This also means that the argument parsing for core dump handlers
is slightly more complicated because they have to deal with the fact
that an attacker that can control the executable name via %E and %e
could pass additional arguments, including command-line options, to the
handler. Usually this is easy to deal with by merging the remaining
arguments after an options termination indicator but it is very
unlikely that core dump handler implementers are aware of the issue.

Theoretically hostnames with %h could also be split up but in practice
they do not appear to be allowed to contain spaces.

Steps to reproduce:

   $ cat foo 
   #!/bin/sh
   printf "%s~" "$@" >> /var/log/core
   echo >> /var/log/core

   $ chmod a+rx foo

   $ sudo sysctl kernel.core_pattern="|`pwd`/foo %E"
   kernel.core_pattern = |/home/pabs/foo %E

   $ cp /bin/sleep 'sleep with spaces'

   $ ./sleep\ with\ spaces 55555 &
   [1] 16041

   $ kill -SEGV %1
   [1]+  Segmentation fault      (core dumped) ./sleep\ with\ spaces 55555

Incorrect results:

   $ cat /var/log/core
   !home!pabs!sleep~with~spaces~

Correct results:

   $ cat /var/log/core
   !home!pabs!sleep with spaces~

This was originally reported by Jakub Wilk <jwilk@jwilk.net>:
<20190312145043.jxjoj66kqssptolr@jwilk.net>
https://bugs.debian.org/924398

-- 
bye,
pabs

https://bonedaddy.net/pabs3/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19  6:06 Paul Wise [this message]
2019-05-20  9:01 ` [PATCH] coredump: Split pipe command whitespace before expanding template Paul Wise
2019-05-20 15:14   ` kbuild test robot
2019-05-21  0:37     ` Paul Wise

Reply instructions:

You may reply publically 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=c8b7ecb8508895bf4adb62a748e2ea2c71854597.camel@bonedaddy.net \
    --to=pabs3@bonedaddy.net \
    --cc=jwilk@jwilk.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox