From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Takashi Iwai <tiwai@suse.de>,
Mauro Carvalho Chehab <mchehab@s-opensource.com>
Subject: [PATCH 4.8 30/37] xc2028: Fix use-after-free bug properly
Date: Wed, 30 Nov 2016 10:30:07 +0100 [thread overview]
Message-ID: <20161130092731.113714372@linuxfoundation.org> (raw)
In-Reply-To: <20161130092729.623248210@linuxfoundation.org>
4.8-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <tiwai@suse.de>
commit 22a1e7783e173ab3d86018eb590107d68df46c11 upstream.
The commit 8dfbcc4351a0 ("[media] xc2028: avoid use after free") tried
to address the reported use-after-free by clearing the reference.
However, it's clearing the wrong pointer; it sets NULL to
priv->ctrl.fname, but it's anyway overwritten by the next line
memcpy(&priv->ctrl, p, sizeof(priv->ctrl)).
OTOH, the actual code accessing the freed string is the strcmp() call
with priv->fname:
if (!firmware_name[0] && p->fname &&
priv->fname && strcmp(p->fname, priv->fname))
free_firmware(priv);
where priv->fname points to the previous file name, and this was
already freed by kfree().
For fixing the bug properly, this patch does the following:
- Keep the copy of firmware file name in only priv->fname,
priv->ctrl.fname isn't changed;
- The allocation is done only when the firmware gets loaded;
- The kfree() is called in free_firmware() commonly
Fixes: commit 8dfbcc4351a0 ('[media] xc2028: avoid use after free')
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/media/tuners/tuner-xc2028.c | 37 +++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -281,6 +281,14 @@ static void free_firmware(struct xc2028_
int i;
tuner_dbg("%s called\n", __func__);
+ /* free allocated f/w string */
+ if (priv->fname != firmware_name)
+ kfree(priv->fname);
+ priv->fname = NULL;
+
+ priv->state = XC2028_NO_FIRMWARE;
+ memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
+
if (!priv->firm)
return;
@@ -291,9 +299,6 @@ static void free_firmware(struct xc2028_
priv->firm = NULL;
priv->firm_size = 0;
- priv->state = XC2028_NO_FIRMWARE;
-
- memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
}
static int load_all_firmwares(struct dvb_frontend *fe,
@@ -884,9 +889,8 @@ read_not_reliable:
return 0;
fail:
- priv->state = XC2028_NO_FIRMWARE;
+ free_firmware(priv);
- memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
if (retry_count < 8) {
msleep(50);
retry_count++;
@@ -1332,11 +1336,8 @@ static int xc2028_dvb_release(struct dvb
mutex_lock(&xc2028_list_mutex);
/* only perform final cleanup if this is the last instance */
- if (hybrid_tuner_report_instance_count(priv) == 1) {
+ if (hybrid_tuner_report_instance_count(priv) == 1)
free_firmware(priv);
- kfree(priv->ctrl.fname);
- priv->ctrl.fname = NULL;
- }
if (priv)
hybrid_tuner_release_state(priv);
@@ -1399,19 +1400,8 @@ static int xc2028_set_config(struct dvb_
/*
* Copy the config data.
- * For the firmware name, keep a local copy of the string,
- * in order to avoid troubles during device release.
*/
- kfree(priv->ctrl.fname);
- priv->ctrl.fname = NULL;
memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
- if (p->fname) {
- priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
- if (priv->ctrl.fname == NULL) {
- rc = -ENOMEM;
- goto unlock;
- }
- }
/*
* If firmware name changed, frees firmware. As free_firmware will
@@ -1426,10 +1416,15 @@ static int xc2028_set_config(struct dvb_
if (priv->state == XC2028_NO_FIRMWARE) {
if (!firmware_name[0])
- priv->fname = priv->ctrl.fname;
+ priv->fname = kstrdup(p->fname, GFP_KERNEL);
else
priv->fname = firmware_name;
+ if (!priv->fname) {
+ rc = -ENOMEM;
+ goto unlock;
+ }
+
rc = request_firmware_nowait(THIS_MODULE, 1,
priv->fname,
priv->i2c_props.adap->dev.parent,
next prev parent reply other threads:[~2016-11-30 9:32 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20161130093010epcas2p3047cf63814e74dfcc79f43d37b446ae0@epcas2p3.samsung.com>
2016-11-30 9:29 ` [PATCH 4.8 00/37] 4.8.12-stable review Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 07/37] usb: chipidea: move the lock initialization to core file Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 08/37] USB: serial: cp210x: add ID for the Zone DPMX Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 09/37] USB: serial: ftdi_sio: add support for TI CC3200 LaunchPad Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 10/37] Fix USB CB/CBI storage devices with CONFIG_VMAP_STACK=y Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 11/37] scsi: mpt3sas: Fix secure erase premature termination Greg Kroah-Hartman
2016-11-30 16:49 ` Martin K. Petersen
2016-12-01 7:10 ` Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 12/37] tile: avoid using clocksource_cyc2ns with absolute cycle count Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 13/37] cfg80211: limit scan results cache size Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 15/37] drm/radeon: fix power state when port pm is unavailable (v2) Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 16/37] apparmor: fix change_hat not finding hat after policy replacement Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 17/37] NFSv4.x: hide array-bounds warning Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 18/37] x86/fpu: Fix invalid FPU ptrace state after execve() Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 19/37] x86/traps: Ignore high word of regs->cs in early_fixup_exception() Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 20/37] perf/core: Fix address filter parser Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 21/37] perf/x86/intel: Cure bogus unwind from PEBS entries Greg Kroah-Hartman
2016-11-30 9:29 ` [PATCH 4.8 22/37] thermal/powerclamp: add back module device table Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 23/37] parisc: Fix races in parisc_setup_cache_timing() Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 24/37] parisc: Switch to generic sched_clock implementation Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 25/37] parisc: Fix race in pci-dma.c Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 26/37] parisc: Also flush data TLB in flush_icache_page_asm Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 27/37] mmc: sdhci-of-esdhc: fixup PRESENT_STATE read Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 28/37] mpi: Fix NULL ptr dereference in mpi_powm() [ver #3] Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 29/37] X.509: Fix double free in x509_cert_parse() " Greg Kroah-Hartman
2016-11-30 9:30 ` Greg Kroah-Hartman [this message]
2016-11-30 9:30 ` [PATCH 4.8 31/37] device-dax: check devm_nsio_enable() return value Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 32/37] device-dax: fail all private mapping attempts Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 33/37] powerpc: Set missing wakeup bit in LPCR on POWER9 Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 34/37] powerpc/mm: Fixup kernel read only mapping Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 35/37] powerpc/boot: Fix the early OPAL console wrappers Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 36/37] can: bcm: fix support for CAN FD frames Greg Kroah-Hartman
2016-11-30 9:30 ` [PATCH 4.8 37/37] mm, oom: stop pre-mature high-order OOM killer invocations Greg Kroah-Hartman
[not found] ` <20161130092730.460938123@linuxfoundation.org>
2016-11-30 10:51 ` [PATCH 4.8 14/37] drm/amdgpu: fix power state when port pm is unavailable Peter Wu
2016-11-30 11:53 ` Greg Kroah-Hartman
2016-12-05 0:11 ` Peter Wu
2016-12-05 14:46 ` Greg Kroah-Hartman
2016-11-30 16:04 ` [PATCH 4.8 00/37] 4.8.12-stable review Shuah Khan
2016-12-01 7:14 ` Greg Kroah-Hartman
2016-11-30 23:34 ` Guenter Roeck
2016-12-01 7:15 ` Greg Kroah-Hartman
[not found] ` <583ed167.6602c20a.c3129.a6b8@mx.google.com>
[not found] ` <m2oa0wkjlk.fsf@baylibre.com>
2016-12-01 7:11 ` 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=20161130092731.113714372@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@s-opensource.com \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.de \
/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).