Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3187157pxb; Sun, 31 Jan 2021 07:14:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfQ4Rf7o75M0AikPEHV5qH7eKvUuji88UQBlie1gLCaHo8GZHonPcpQT5vbnLqNgicfq9b X-Received: by 2002:a17:906:7689:: with SMTP id o9mr13712878ejm.324.1612106074309; Sun, 31 Jan 2021 07:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612106074; cv=none; d=google.com; s=arc-20160816; b=ij1AOCfXzqyE5LGLbRG9xNUCo5m4IlowOdp4H2VHZEyg0aUisiDLUeNKGlMpdGXAG3 /u+Op/qexK+6zw5+RFa5avSfNamYCblenXq08913Fvwrpmfjgv5054b2ZlrnLDGkqtzQ rc1rwFR7NyvatqiUsQNjzPWmx+MbvI6ro9Z6KirsQ2LjuUp00JK8oHvpRSchiffHLhtI yvO9K+dVbHW6PSu7ieOeuf/71LrKRGufvaEK0Qs5Ek0Ahs8lWGHrwGAnbVtU+ek3UCJV dJx2vTHMrq0Tc/0KrK7Erd1aIaleI+17+StcecRJU6PWG4YM8jrDu5sJg/SaIPKaKTZv ut9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=t6fbwVbeaGm3WnU3VLfaJT2UqCXAuKSHcUtl9UpnJ/8=; b=tXtaWoICpHt9pWf1N0Z+hjt1cRrwIlI/+w1QnT6fnkTI2qJSiCV6x1L/gWLXn+eTSF qP6JorRmednxTKYEvwxZAk7TOOjNvd6YIWr22Wh96cTCGxeUxjtPHGLa5QHU6RB9HVlk PobuJAWFFPyXYMwioDvBUibEr+zxRZniz331H/bjEuRi0fvN7tiHWhHXhCM6kft49yA7 a1UV3a6MS74bTlRoyLxtD3p2H7KeajhL+zR760ZM/7png62ofKbEcaOosqzT2xV7nK3X L5biJYb6EKEQBtdNsIK+irgWDckZzH5A5sbJ/RokJ+zBjaGGjyY1GD9nZsl+2rPh1+SP 4oZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mess.org header.s=2020 header.b=VEUOuZBt; 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 rh4si8858693ejb.538.2021.01.31.07.13.55; Sun, 31 Jan 2021 07:14:34 -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; dkim=fail header.i=@mess.org header.s=2020 header.b=VEUOuZBt; 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 S232670AbhAaPLz (ORCPT + 99 others); Sun, 31 Jan 2021 10:11:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbhAaPFt (ORCPT ); Sun, 31 Jan 2021 10:05:49 -0500 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7247C061573; Sun, 31 Jan 2021 07:04:58 -0800 (PST) Received: by gofer.mess.org (Postfix, from userid 1000) id AA422C6357; Sun, 31 Jan 2021 15:04:56 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1612105496; bh=d4JxLPLb7QEMGGaZmAC9Qj9a1O3NSuHHwtJaFZNe/S0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VEUOuZBt7t8frDe9KRUOxvqiiVfpmthfoiNRjx7wXSH2XcPSAcBAF03asiw5kA5RD 1/iOYrkSnl2f7oLwno7zoaKbKpHcL2xGvI25B2CXeeacf/pUHwzi00WVMrVmhKLwMu yJ5eBo7Bfs5Ci8+uBgg7163/c1X29vfMviyiO5eI3UW4z7W4SbkY9igvTSqv4kOFVq ahi/x90PvpONcdiHNyAg2NOFzPSk1RL+DZ6z3yYLEmnOYn0LPjTuSsQ3BpHjyBM9DN FkpcQ3uX2HNf9iSVvMiDbixIfMzeqQSN0nNILP6FMpRU6uyYxVbsNkIpBgJ4kwWfTA GFPnLnO9vg5rQ== Date: Sun, 31 Jan 2021 15:04:56 +0000 From: Sean Young To: Robert Foss Cc: Takashi Iwai , Mauro Carvalho Chehab , linux-media , linux-kernel , Stefan Seyfried Subject: Re: [PATCH 2/2] media: dvb-usb: Fix use-after-free access Message-ID: <20210131150456.GB4886@gofer.mess.org> References: <20210120102057.21143-1-tiwai@suse.de> <20210120102057.21143-3-tiwai@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Takashi, On Fri, Jan 22, 2021 at 04:47:44PM +0100, Robert Foss wrote: > Hey Takashi, > > This patch is generating a checkpatch warning, but I think it is > spurious and can be ignored. The checkpatch warning isn't superious and should really be corrected. > > Other than that, this looks good to me. > Reviewed-by: Robert Foss > > On Wed, 20 Jan 2021 at 12:51, Takashi Iwai wrote: > > > > 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 > > Cc: > > Signed-off-by: Takashi Iwai Thank you for your patch. Unfortunately, it depends on the first patch in the series, which I think has problems (see email about this). Thanks Sean > > --- > > 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 5befec87f26a..07ff9b4d2f34 100644 > > --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c > > +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c > > @@ -255,27 +255,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 > >