Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2491073pxj; Mon, 10 May 2021 04:22:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz6JquXlHwEUXPa5z2T5X2iIRs7BY3F1rFtkrm5UYrfVE+peO65zRV249Hd/8PVz1rpNK6 X-Received: by 2002:a92:1304:: with SMTP id 4mr20926103ilt.126.1620645776573; Mon, 10 May 2021 04:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645776; cv=none; d=google.com; s=arc-20160816; b=Nb3lfSvhm3GA9wfxCuyOQdwlpTZTPal/JE9bC145cmy+g8xlbd9H7j+g90GfzZ+5yh MySGQy67dt2Q2O/sI63VHARN+IAny32W6a0/U3J69boKj2jzyb7e3QjVz7J3WwBUemCI wZBilDtOdH/22LytLsLZGx6JCS/NtRYBDuIGJe2BAL7ByBcElmwBt8ahHe6It0/7MQeh XcyCq5D5KsCSEFdRidPxMKDS8viTt33inP64P3fsX8ahuYdv9r1Tqd5TYRgxq5ULOmFF 4HtL23GhPBQoYUxUIETvV++WZ2HHU8h2EKcoTeSCROYlq684UA1ruPYsufh37/tb77IE oISQ== 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=w0M+1RCwrSNEUxRDipYIKnq5thj+b0XjDRC0ZptOkbaR6t7KwlXCplq0gVDS5eFCSz jXagemm7cNo9cJvLkIiHbW+uhXcKPVVnE1rotbw+iXvtOZi480ae6MvO7VLnT1SoXx1F f3OdvqatDhGOyhREXo54lfiS3cZ9ijH1I9hx03MjLWY2rJ+LbRmv33POnr0nU4+KLClF m2hOUIYvgEfK2R17rkZSNNSvNSbdEYeo+QcUkl5FqG4OCKLbPphisliWgjDiqgVMZGjs 7dt8Z2wHq+60jKK0hPspxNJNZhnUvdHw5CorvYkm9kbhSNZo4U3rzDPtUfiwrKRm2RMh tB2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RfX2Ftqn; 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 f4si16857365ilq.17.2021.05.10.04.22.43; Mon, 10 May 2021 04:22:56 -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=RfX2Ftqn; 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 S238865AbhEJLUP (ORCPT + 99 others); Mon, 10 May 2021 07:20:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:52682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234017AbhEJKzq (ORCPT ); Mon, 10 May 2021 06:55:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A39EB6196E; Mon, 10 May 2021 10:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643404; bh=vmRwiyypgVbsZ/+3FOlU9DN916jLITD/t3fXolfSu7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfX2Ftqn8ZA/agcYJZTwvFuqFtYMfoPFfo0VYFkiTIiNiGy6qYXpbrmAyCYiPb/qP u1xtUOuHiWwSJXxTT5ZCpY7kn0mYehNpA5XwHtAYuAceG2adyE11I/52mgOl3KK4I9 vC8aX20cXTP1TItu4j7i909yDpt9Tdd2swUAH+rM= 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.10 274/299] media: dvb-usb: Fix use-after-free access Date: Mon, 10 May 2021 12:21:11 +0200 Message-Id: <20210510102013.983789138@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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;