Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2709045pxj; Mon, 10 May 2021 09:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/onFt0ae/MJwLgSVmrqUoxJI90lDGlfxJ9iTg4G0XNXCFXGYoDLj++OyHgD/urSbRkR+b X-Received: by 2002:a5e:a902:: with SMTP id c2mr15707419iod.80.1620662501299; Mon, 10 May 2021 09:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620662501; cv=none; d=google.com; s=arc-20160816; b=fQgVJO5foPlT7BbFHKKVhJoEgkwT1JeGy/PTWAvr+ta9qduQmKxHPpyp/8XWUo6eQ6 7AY5Ml6hWIxP1ZhWG18m1F3dSt2NHqn9zItVaWFBY0HQNaxpwgoFh3eGjaPBBROmhaCd IKhYwYRrOe+mtTdWfwmcAGHrq/nYf7Phca0N/FZa3CpW9S6NP6vxgM3f0w9kQlyzti5t zAOY7pS4uxEb52a70VENp/gaAz//QvbLDfz+qqjNN9H+Ol5ExaEw/p6kw61CfgvSwWzm j3bGqWjTebuDfXn788nJdvkXnGAlov7XSVuxFbOPrfV+zMPUpLburDvNtEyQMplSRlvO 4s8A== 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=M9a+kf4RHoil6hpvYfM+pJNOd7xigcwYmSzSvQnkkd3ZhCpkDzczA0EAWesIijY2I/ 0gCLGwZo/gmKDueACo0mWs+S0Fz8Pm3lDdZ24u5uCOsdWhhnamwfP5Y48Tx26fr0r27N bI2p2dB7VUOLbcRozfaa9lfIzp3hcekypAYoZlpo+Fuiwi+EGpzmAM1bh0odTt5JwW10 uTHdg4veSK8MkQX9D60ewDKAcfaey0PRiGRD83mX5n4K7L9e0JE2+Zpl7LaoVEGVlLXE gOYOj58YJ56fjPrmB4+oZeRS+TwPMeWp5HRo19YqsqmrYs0EKJOv4DGKhn9YE51h5XSd /CvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qJOSTOsX; 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 y5si15032358ill.127.2021.05.10.09.01.27; Mon, 10 May 2021 09:01:41 -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=qJOSTOsX; 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 S1349007AbhEJMr7 (ORCPT + 99 others); Mon, 10 May 2021 08:47:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:33952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238220AbhEJLRQ (ORCPT ); Mon, 10 May 2021 07:17:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFBE3617ED; Mon, 10 May 2021 11:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620645172; bh=vmRwiyypgVbsZ/+3FOlU9DN916jLITD/t3fXolfSu7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJOSTOsXRkeOoeYfXfTcIOrf8nsgVX9DG2Z1SOARdHGLww6KxXIKc0D+kfchHJpG/ 58xb4nnVyBp6WfTnumjiYm0Hda/ZzwYYJixTyth5TYid1ig5kjZGvhURvlJbx8N5IM 6p8WS76oq7XlFWip9itUPKLOxALy8bb4cPP9QfFE= 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.12 347/384] media: dvb-usb: Fix use-after-free access Date: Mon, 10 May 2021 12:22:16 +0200 Message-Id: <20210510102026.207596219@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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;