Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2523270pxj; Mon, 10 May 2021 05:09:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwojdkqr9rB/R4Zv9s5ANZLJaJGNJBlIJTSIiSMNV0mgTB0LS70qw8brnINKPkHiRSnvylp X-Received: by 2002:a17:906:c0c6:: with SMTP id bn6mr24882792ejb.436.1620648543270; Mon, 10 May 2021 05:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620648543; cv=none; d=google.com; s=arc-20160816; b=p16GXCkeyTb7LbTrYKap3FfDugOoNngEYWqEpV4BDrCPgSYxiXBjsZ5xUCvxPwfb6T 4gdTSKb8ZI9Zdptp5nvY1mWQ6l2tSeR1N3nxK12AaaovmtPpteQux4hZUstnIGbxSRDe sISON1mjv7uRoDR/O5CjlSm7SxIBVZ/EzMZg38nfEtPtO56VG/k+tqHvnTcqCKHz8iuk 4fGKPsH9eLlN0Q1gagnmNUO5zjA9gA0RQBwKJxBy/ruE+Se4AwYtI6fg6Cjx8n5bEY/C JdO852GHR8d73/hp7TYpY/tXrhyX9UMXOWk4K23ai1qAR3R7FS+1YW8G0VdToroNdXrR 0DVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fUPGUaj0oHVKLeGKHe3e4sg6yRTkMe7q7DzHYKC+n34=; b=oOaV5lWA0+wuhZVtr8hEiwH/KLy2GWyiDcdJi149Obgvk0gm1RIoDcn0zLJMwAYFWm 5i7ZWNgI52jqnNy3BW1AGU8QTSS5LqK/JZvzB/SYe5E/AO8W0C5QWrIrC4djjx83S2Gn VNmWzSERSVlqM1o4+GPDQdW3/Lg5kzqIp03nzjiy5QcnxyUuvbbwrdvASXh1/wwJRDmh PfcWdiCL0Vd09CR8NiKPRuy40R2YGrKLEc4y7ArhSB66cTIQ3FalBp91dCRyf6fl6xYq kU3Gpz6NEKINkoIpb71p6WXVF8PpuVRVh6bZ8ngx52w60715EeoWdG0HIuMs7Xbf2yft 1huA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OLsZ1KAo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di2si13764746edb.32.2021.05.10.05.08.38; Mon, 10 May 2021 05:09:03 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OLsZ1KAo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243895AbhEJL5g (ORCPT + 99 others); Mon, 10 May 2021 07:57:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235768AbhEJLGF (ORCPT ); Mon, 10 May 2021 07:06:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B536613D3; Mon, 10 May 2021 10:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644169; bh=vmRwiyypgVbsZ/+3FOlU9DN916jLITD/t3fXolfSu7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLsZ1KAokE8yAH498jokP9E3NdLxh730g7PSrPAy8FUtEo+EAsTSz70moNQd8jEF/ F1X9v9QgRI+3AxEW2ebbqzlmiKE99ZDdfdRMPeYACaloNbETThOVpn7LFRiTG5CT7v I28peqptxfNP3Pm1lusfajxrwGLAvxuDfI+4jw5M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Foss , Takashi Iwai , Sean Young , Mauro Carvalho Chehab , Stefan Seyfried Subject: [PATCH 5.11 314/342] media: dvb-usb: Fix use-after-free access Date: Mon, 10 May 2021 12:21:44 +0200 Message-Id: <20210510102020.488034321@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit c49206786ee252f28b7d4d155d1fff96f145a05d upstream. 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 Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/dvb-usb/dvb-usb-init.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -267,27 +267,30 @@ int dvb_usb_device_init(struct usb_inter if (du != NULL) *du = NULL; - if ((desc = dvb_usb_find_device(udev, props, &cold)) == NULL) { + d = kzalloc(sizeof(*d), 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;