All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Andrey Ryabinin <aryabinin@virtuozzo.com>,
	David Howells <dhowells@redhat.com>,
	Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	linux-ima-devel@lists.sourceforge.net,
	James Morris <james.l.morris@oracle.com>
Subject: [PATCH 3.18 35/35] mpi: Fix NULL ptr dereference in mpi_powm() [ver #3]
Date: Fri,  6 Oct 2017 11:25:15 +0200	[thread overview]
Message-ID: <20171006092404.197692818@linuxfoundation.org> (raw)
In-Reply-To: <20171006092402.810400570@linuxfoundation.org>

3.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Andrey Ryabinin <aryabinin@virtuozzo.com>

commit f5527fffff3f002b0a6b376163613b82f69de073 upstream.

This fixes CVE-2016-8650.

If mpi_powm() is given a zero exponent, it wants to immediately return
either 1 or 0, depending on the modulus.  However, if the result was
initalised with zero limb space, no limbs space is allocated and a
NULL-pointer exception ensues.

Fix this by allocating a minimal amount of limb space for the result when
the 0-exponent case when the result is 1 and not touching the limb space
when the result is 0.

This affects the use of RSA keys and X.509 certificates that carry them.

BUG: unable to handle kernel NULL pointer dereference at           (null)
IP: [<ffffffff8138ce5d>] mpi_powm+0x32/0x7e6
PGD 0
Oops: 0002 [#1] SMP
Modules linked in:
CPU: 3 PID: 3014 Comm: keyctl Not tainted 4.9.0-rc6-fscache+ #278
Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014
task: ffff8804011944c0 task.stack: ffff880401294000
RIP: 0010:[<ffffffff8138ce5d>]  [<ffffffff8138ce5d>] mpi_powm+0x32/0x7e6
RSP: 0018:ffff880401297ad8  EFLAGS: 00010212
RAX: 0000000000000000 RBX: ffff88040868bec0 RCX: ffff88040868bba0
RDX: ffff88040868b260 RSI: ffff88040868bec0 RDI: ffff88040868bee0
RBP: ffff880401297ba8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000047 R11: ffffffff8183b210 R12: 0000000000000000
R13: ffff8804087c7600 R14: 000000000000001f R15: ffff880401297c50
FS:  00007f7a7918c700(0000) GS:ffff88041fb80000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 0000000401250000 CR4: 00000000001406e0
Stack:
 ffff88040868bec0 0000000000000020 ffff880401297b00 ffffffff81376cd4
 0000000000000100 ffff880401297b10 ffffffff81376d12 ffff880401297b30
 ffffffff81376f37 0000000000000100 0000000000000000 ffff880401297ba8
Call Trace:
 [<ffffffff81376cd4>] ? __sg_page_iter_next+0x43/0x66
 [<ffffffff81376d12>] ? sg_miter_get_next_page+0x1b/0x5d
 [<ffffffff81376f37>] ? sg_miter_next+0x17/0xbd
 [<ffffffff8138ba3a>] ? mpi_read_raw_from_sgl+0xf2/0x146
 [<ffffffff8132a95c>] rsa_verify+0x9d/0xee
 [<ffffffff8132acca>] ? pkcs1pad_sg_set_buf+0x2e/0xbb
 [<ffffffff8132af40>] pkcs1pad_verify+0xc0/0xe1
 [<ffffffff8133cb5e>] public_key_verify_signature+0x1b0/0x228
 [<ffffffff8133d974>] x509_check_for_self_signed+0xa1/0xc4
 [<ffffffff8133cdde>] x509_cert_parse+0x167/0x1a1
 [<ffffffff8133d609>] x509_key_preparse+0x21/0x1a1
 [<ffffffff8133c3d7>] asymmetric_key_preparse+0x34/0x61
 [<ffffffff812fc9f3>] key_create_or_update+0x145/0x399
 [<ffffffff812fe227>] SyS_add_key+0x154/0x19e
 [<ffffffff81001c2b>] do_syscall_64+0x80/0x191
 [<ffffffff816825e4>] entry_SYSCALL64_slow_path+0x25/0x25
Code: 56 41 55 41 54 53 48 81 ec a8 00 00 00 44 8b 71 04 8b 42 04 4c 8b 67 18 45 85 f6 89 45 80 0f 84 b4 06 00 00 85 c0 75 2f 41 ff ce <49> c7 04 24 01 00 00 00 b0 01 75 0b 48 8b 41 18 48 83 38 01 0f
RIP  [<ffffffff8138ce5d>] mpi_powm+0x32/0x7e6
 RSP <ffff880401297ad8>
CR2: 0000000000000000
---[ end trace d82015255d4a5d8d ]---

Basically, this is a backport of a libgcrypt patch:

	http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=patch;h=6e1adb05d290aeeb1c230c763970695f4a538526

Fixes: cdec9cb5167a ("crypto: GnuPG based MPI lib - source files (part 1)")
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>
cc: linux-ima-devel@lists.sourceforge.net
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 lib/mpi/mpi-pow.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/lib/mpi/mpi-pow.c
+++ b/lib/mpi/mpi-pow.c
@@ -64,8 +64,13 @@ int mpi_powm(MPI res, MPI base, MPI exp,
 	if (!esize) {
 		/* Exponent is zero, result is 1 mod MOD, i.e., 1 or 0
 		 * depending on if MOD equals 1.  */
-		rp[0] = 1;
 		res->nlimbs = (msize == 1 && mod->d[0] == 1) ? 0 : 1;
+		if (res->nlimbs) {
+			if (mpi_resize(res, 1) < 0)
+				goto enomem;
+			rp = res->d;
+			rp[0] = 1;
+		}
 		res->sign = 0;
 		goto leave;
 	}

  parent reply	other threads:[~2017-10-06  9:26 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06  9:24 [PATCH 3.18 00/35] 3.18.74-stable review Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 01/35] drm: bridge: add DT bindings for TI ths8135 Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 02/35] RDS: RDMA: Fix the composite message user notification Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 03/35] MIPS: Ensure bss section ends on a long-aligned address Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 04/35] MIPS: kexec: Do not reserve invalid crashkernel memory on boot Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 06/35] hwmon: (gl520sm) Fix overflows and crash seen when writing into limit attributes Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 07/35] ARM: 8635/1: nommu: allow enabling REMAP_VECTORS_TO_RAM Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 08/35] tty: goldfish: Fix a parameter of a call to free_irq Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 09/35] IB/ipoib: Fix deadlock over vlan_mutex Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 10/35] IB/ipoib: rtnl_unlock can not come after free_netdev Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 11/35] IB/ipoib: Replace list_del of the neigh->list with list_del_init Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 12/35] USB: serial: mos7720: fix control-message error handling Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 13/35] USB: serial: mos7840: " Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 14/35] pinctrl: mvebu: Use seq_puts() in mvebu_pinconf_group_dbg_show() Greg Kroah-Hartman
2017-10-06  9:32   ` Joe Perches
2017-10-06  9:42     ` Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 15/35] partitions/efi: Fix integer overflow in GPT size calculation Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 16/35] audit: log 32-bit socketcalls Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 17/35] net: core: Prevent from dereferencing null pointer when releasing SKB Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 18/35] net/packet: check length in getsockopt() called with PACKET_HDRLEN Greg Kroah-Hartman
2017-10-06  9:24 ` [PATCH 3.18 19/35] team: fix memory leaks Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 21/35] mmc: sdio: fix alignment issue in struct sdio_func Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 22/35] netfilter: invoke synchronize_rcu after set the _hook_ to NULL Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 23/35] [media] exynos-gsc: Do not swap cb/cr for semi planar formats Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 24/35] netfilter: nfnl_cthelper: fix incorrect helper->expect_class_max Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 25/35] parisc: perf: Fix potential NULL pointer dereference Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 26/35] rds: ib: add error handle Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 27/35] md/raid10: submit bio directly to replacement disk Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 28/35] xfs: remove kmem_zalloc_greedy Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 29/35] libata: transport: Remove circular dependency at free time Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 30/35] IB/qib: fix false-postive maybe-uninitialized warning Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 31/35] ALSA: au88x0: avoid theoretical uninitialized access Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 32/35] [media] ttpci: address stringop overflow warning Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 33/35] staging: nvec: remove duplicated const Greg Kroah-Hartman
2017-10-06  9:25 ` [PATCH 3.18 34/35] crypto: algif_skcipher - Load TX SG list after waiting Greg Kroah-Hartman
2017-10-06  9:25 ` Greg Kroah-Hartman [this message]
2017-10-06 14:03 ` [PATCH 3.18 00/35] 3.18.74-stable review Guenter Roeck
2017-10-07  9:38   ` Greg Kroah-Hartman
2017-10-06 17:30 ` Shuah Khan
2017-10-07  9:04   ` Greg Kroah-Hartman
2017-10-07  9:40 ` Greg Kroah-Hartman
2017-10-07 14:43   ` Guenter Roeck
2017-10-08  7:20     ` Greg Kroah-Hartman

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=20171006092404.197692818@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=dhowells@redhat.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=james.l.morris@oracle.com \
    --cc=linux-ima-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.