Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3652747pxb; Mon, 1 Feb 2021 00:37:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjtpMu1UeJA3vUuEdWCNkdv97/ZRrvcEOxOL3KJ2MzNbvF6vDYdXsfQv/nuFSn1HPdRknr X-Received: by 2002:a17:906:b09a:: with SMTP id x26mr16877727ejy.199.1612168638654; Mon, 01 Feb 2021 00:37:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612168638; cv=none; d=google.com; s=arc-20160816; b=FGmYVhzwdyFe09lee9UaJJ8v6g68dbZIIONDepC5G+yYxEcsulryUreVUnA+tSe8qR XpBO8OyBWDi/WGfrZAXFoqpwqWfArodAjlMvG7ak6wfGZ+YlFowpoU/OYrzraZyk+6Wq 5TETi1G/UV4+S68hNvKkUsybb8IDX3l05Hm67K6+TX9HGY9yrntGoIq9HaNmS4Lwt/UU LfDfYv5bckO5jYtFAYPeVgZ+HOQavNY1pISAJqZFUHpmtbNLCQODcZJ3J7sCk3VL7XBH r0o6MFVKAfqUrOW1CzNMomfFuEhejePfc6EOOzrWIWEfBFniakCgg4aVOtbijlSXt5gM iFow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vUGEG/KmPf9K9Q5AEokGPW1YdtGUsBvpOvVsGZhSIX4=; b=R/UUJr87jLprVTxJdHTDO/ZLeftkw1t6dfu3QTjxdEVGwwiFs06BgPGL+s8ppGgBwg 6vCNJ8qBuqF2qVPZO/ojESdHjOeMWfIkgL+s41ZlIB/2+lSc1S1AggGk6AHkiX2Ogh31 cm4SL8CU+6q3CSkSXWnfz24to9wZoFkOAzjTX8MBp23ZHRzxNdcW8bICrUkR606ADyr0 HjC3Rpxx1Vr4f1dlzLI/7wBlnKr/otP0a4rQouJTpDWYDKMSyiswiQlzzdwjazDpmzqI +2CwT/ZJ5hMTS3nAmPw95Jkwt1dCMqlsCidvYpvqNaN7EZ4K7w1eCFVmV4RVKpuliXob gebA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si10587893edn.0.2021.02.01.00.36.54; Mon, 01 Feb 2021 00:37:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232530AbhBAIdg (ORCPT + 99 others); Mon, 1 Feb 2021 03:33:36 -0500 Received: from mx2.suse.de ([195.135.220.15]:57308 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232032AbhBAIdc (ORCPT ); Mon, 1 Feb 2021 03:33:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 98396ADD3; Mon, 1 Feb 2021 08:32:50 +0000 (UTC) From: Takashi Iwai To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Seyfried , Robert Foss , Sean Young Subject: [PATCH v2 2/2] media: dvb-usb: Fix use-after-free access Date: Mon, 1 Feb 2021 09:32:47 +0100 Message-Id: <20210201083247.10760-3-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210201083247.10760-1-tiwai@suse.de> References: <20210201083247.10760-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dvb_usb_device_init() copies the properties to the own data, so that the callers can release the original properties later (as done in the commit 299c7007e936 "media: dw2102: Fix memleak on sequence of probes"). However, it also stores dev->desc pointer that is a reference to the original properties data. Since dev->desc is referred later, it may result in use-after-free, in the worst case, leading to a kernel Oops as reported. This patch addresses the problem by allocating and copying the properties at first, then get the desc from the copied properties. Reported-and-tested-by: Stefan Seyfried BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1181104 Reviewed-by: Robert Foss Cc: Signed-off-by: Takashi Iwai --- v1->v2: Only tag update drivers/media/usb/dvb-usb/dvb-usb-init.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c index c78158d12540..12983baf6c3f 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -264,27 +264,30 @@ int dvb_usb_device_init(struct usb_interface *intf, if (du != NULL) *du = NULL; - if ((desc = dvb_usb_find_device(udev, props, &cold)) == NULL) { + d = kzalloc(sizeof(struct dvb_usb_device), GFP_KERNEL); + if (!d) { + err("no memory for 'struct dvb_usb_device'"); + return -ENOMEM; + } + + memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties)); + + desc = dvb_usb_find_device(udev, &d->props, &cold); + if (!desc) { deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n"); - return -ENODEV; + ret = -ENODEV; + goto error; } if (cold) { info("found a '%s' in cold state, will try to load a firmware", desc->name); ret = dvb_usb_download_firmware(udev, props); if (!props->no_reconnect || ret != 0) - return ret; + goto error; } info("found a '%s' in warm state.", desc->name); - d = kzalloc(sizeof(struct dvb_usb_device), GFP_KERNEL); - if (d == NULL) { - err("no memory for 'struct dvb_usb_device'"); - return -ENOMEM; - } - d->udev = udev; - memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties)); d->desc = desc; d->owner = owner; -- 2.26.2