linux-kernel.vger.kernel.org archive mirror
 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,
	syzbot+1e925b4b836afe85a1c6@syzkaller-ppc64.appspotmail.com,
	syzbot+587b2421926808309d21@syzkaller-ppc64.appspotmail.com,
	syzbot+58320b7171734bf79d26@syzkaller.appspotmail.com,
	syzbot+d6074fb08bdb2e010520@syzkaller.appspotmail.com,
	Daniel Axtens <dja@axtens.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	David Rientjes <rientjes@google.com>,
	Akash Goel <akash.goel@intel.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Salvatore Bonaccorso <carnil@debian.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.19 07/28] kernel/relay.c: handle alloc_percpu returning NULL in relay_open
Date: Fri,  5 Jun 2020 16:15:09 +0200	[thread overview]
Message-ID: <20200605140252.766450436@linuxfoundation.org> (raw)
In-Reply-To: <20200605140252.338635395@linuxfoundation.org>

From: Daniel Axtens <dja@axtens.net>

commit 54e200ab40fc14c863bcc80a51e20b7906608fce upstream.

alloc_percpu() may return NULL, which means chan->buf may be set to NULL.
In that case, when we do *per_cpu_ptr(chan->buf, ...), we dereference an
invalid pointer:

  BUG: Unable to handle kernel data access at 0x7dae0000
  Faulting instruction address: 0xc0000000003f3fec
  ...
  NIP relay_open+0x29c/0x600
  LR relay_open+0x270/0x600
  Call Trace:
     relay_open+0x264/0x600 (unreliable)
     __blk_trace_setup+0x254/0x600
     blk_trace_setup+0x68/0xa0
     sg_ioctl+0x7bc/0x2e80
     do_vfs_ioctl+0x13c/0x1300
     ksys_ioctl+0x94/0x130
     sys_ioctl+0x48/0xb0
     system_call+0x5c/0x68

Check if alloc_percpu returns NULL.

This was found by syzkaller both on x86 and powerpc, and the reproducer
it found on powerpc is capable of hitting the issue as an unprivileged
user.

Fixes: 017c59c042d0 ("relay: Use per CPU constructs for the relay channel buffer pointers")
Reported-by: syzbot+1e925b4b836afe85a1c6@syzkaller-ppc64.appspotmail.com
Reported-by: syzbot+587b2421926808309d21@syzkaller-ppc64.appspotmail.com
Reported-by: syzbot+58320b7171734bf79d26@syzkaller.appspotmail.com
Reported-by: syzbot+d6074fb08bdb2e010520@syzkaller.appspotmail.com
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Akash Goel <akash.goel@intel.com>
Cc: Andrew Donnellan <ajd@linux.ibm.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Salvatore Bonaccorso <carnil@debian.org>
Cc: <stable@vger.kernel.org>	[4.10+]
Link: http://lkml.kernel.org/r/20191219121256.26480-1-dja@axtens.net
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/relay.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -581,6 +581,11 @@ struct rchan *relay_open(const char *bas
 		return NULL;
 
 	chan->buf = alloc_percpu(struct rchan_buf *);
+	if (!chan->buf) {
+		kfree(chan);
+		return NULL;
+	}
+
 	chan->version = RELAYFS_CHANNEL_VERSION;
 	chan->n_subbufs = n_subbufs;
 	chan->subbuf_size = subbuf_size;



  parent reply	other threads:[~2020-06-05 14:20 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 14:15 [PATCH 4.19 00/28] 4.19.127-rc1 review Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 01/28] Revert "cgroup: Add memory barriers to plug cgroup_rstat_updated() race window" Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 02/28] libnvdimm: Fix endian conversion issues Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 03/28] mm: Fix mremap not considering huge pmd devmap Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 04/28] HID: sony: Fix for broken buttons on DS3 USB dongles Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 05/28] HID: i2c-hid: add Schneider SCL142ALM to descriptor override Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 06/28] p54usb: add AirVasT USB stick device-id Greg Kroah-Hartman
2020-06-05 14:15 ` Greg Kroah-Hartman [this message]
2020-06-05 14:15 ` [PATCH 4.19 08/28] mmc: fix compilation of user API Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 09/28] scsi: ufs: Release clock if DMA map fails Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 10/28] net: dsa: mt7530: set CPU port to fallback mode Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 11/28] airo: Fix read overflows sending packets Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 12/28] drm/i915: fix port checks for MST support on gen >= 11 Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 13/28] scsi: hisi_sas: Check sas_port before using it Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 14/28] powerpc/powernv: Avoid re-registration of imc debugfs directory Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 15/28] spi: dw: use "smp_mb()" to avoid sending spi data error Greg Kroah-Hartman
2020-06-07 20:09   ` Pavel Machek
2020-06-08 11:16     ` Mark Brown
2020-06-10 15:01       ` Pavel Machek
2020-06-05 14:15 ` [PATCH 4.19 16/28] s390/ftrace: save traced function caller Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 17/28] ARC: Fix ICCM & DCCM runtime size checks Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 18/28] ARC: [plat-eznps]: Restrict to CONFIG_ISA_ARCOMPACT Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 19/28] evm: Fix RCU list related warnings Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 20/28] i2c: altera: Fix race between xfer_msg and isr thread Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 21/28] x86/mmiotrace: Use cpumask_available() for cpumask_var_t variables Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 22/28] net: bmac: Fix read of MAC address from ROM Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 23/28] drm/edid: Add Oculus Rift S to non-desktop list Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 24/28] s390/mm: fix set_huge_pte_at() for empty ptes Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 25/28] null_blk: return error for invalid zone size Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 26/28] net/ethernet/freescale: rework quiesce/activate for ucc_geth Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 27/28] net: ethernet: stmmac: Enable interface clocks on probe for IPQ806x Greg Kroah-Hartman
2020-06-05 14:15 ` [PATCH 4.19 28/28] net: smsc911x: Fix runtime PM imbalance on error Greg Kroah-Hartman
2020-06-05 22:19 ` [PATCH 4.19 00/28] 4.19.127-rc1 review Shuah Khan
2020-06-06  6:32 ` Jon Hunter
2020-06-07 11:19   ` Greg Kroah-Hartman
2020-06-06 13:33 ` Guenter Roeck
2020-06-07  5:44 ` Naresh Kamboju
2020-06-08  9:44 ` Chris Paterson

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=20200605140252.766450436@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ajd@linux.ibm.com \
    --cc=akash.goel@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=carnil@debian.org \
    --cc=dja@axtens.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mpe@ellerman.id.au \
    --cc=rientjes@google.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+1e925b4b836afe85a1c6@syzkaller-ppc64.appspotmail.com \
    --cc=syzbot+58320b7171734bf79d26@syzkaller.appspotmail.com \
    --cc=syzbot+587b2421926808309d21@syzkaller-ppc64.appspotmail.com \
    --cc=syzbot+d6074fb08bdb2e010520@syzkaller.appspotmail.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).