Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp385904pxb; Wed, 3 Mar 2021 05:55:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyu9wrOJ8ujNXxQ89Cj8FNM4C3Lxzwt0E+6OBymlHpcVMj0J9OzdDmZGDjSjiF+Ly4cqN6y X-Received: by 2002:a17:906:a944:: with SMTP id hh4mr18621660ejb.479.1614779758702; Wed, 03 Mar 2021 05:55:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614779758; cv=none; d=google.com; s=arc-20160816; b=maB81SpAiwf8M/2g1bM5/dKvK2RFV2miWYoGZe1fb0JelVrAclWkDzNQtLMfUmas0u jvlQ3DJi6kIWCHx31YDzQkv/UjBZi9rNDgNGpEfWbvHH/m4yD+pzIfuWnjdkcylwsBxr LQh3LCUUDLTIJ8+OwEv4wxR4OwlSW4ygKRdNDCeU5owyCovvHq0WT48O/CO6ooemKBXC Pl5rNLI95HIZldZwrplFrRH5WSHh7RicIS9ZeBn5k+Wmlm95DO46Zd/3t80GH9EeZeUq /W0VhIIR+0++82IsaPvJo41+tZFbKc9FzZeruUlVi3+R78PbdyASQkZ41dWEZcXffbUo ScVQ== 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=HyCjDC33hOjOKBARx6ncILaXo6bbuM9nJ3L9ZsNTp3c=; b=DHgIxGzcP0cR7/nepj1BRX+SieCjoR46uQwP9T4NlLtUzBIAAqL4LhLg6vIc8/abg0 AAFhNy3Lsq0orrQbh9pWkvAAmD1JCPZW+4bAa9iTp2p3gHYagu1WE0UjeMe7TyTtrlSk z58XmQprqUa83dyxwzmA1YKrEDdGeHkhFlCadSquPOvEhIfbMzSObcHPzAdCtipnYcAd ihUTB44oCA1DR+Rpc5fse4Gj+3o9B4oIYOu197u4kZhAxT9BlFktGAGg7q05VAWqpNmf ch/9tpvs1hTANRqc1triBVLllEPLTO+dax0QMoACHNYPxN9I6UktjtEVuzZhYLhFlVPz YsrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q0CKc8+1; 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 h27si15341147ejd.660.2021.03.03.05.55.10; Wed, 03 Mar 2021 05:55:58 -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=pass header.i=@linuxfoundation.org header.s=korg header.b=q0CKc8+1; 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 S242710AbhCAUOP (ORCPT + 99 others); Mon, 1 Mar 2021 15:14:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:33342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236519AbhCAREA (ORCPT ); Mon, 1 Mar 2021 12:04:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 018B064F75; Mon, 1 Mar 2021 16:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616752; bh=+1tOzkY9fMdvKcJ5XzkSmdZHuEwUNsMM9VTFsC1ITaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q0CKc8+1BMs7GlVjtGPTnZQcqP6dyBtWj0vxZ4aQgFieDoMbbH792n3lea5Xq0DAU cVrH+cfvCKWOJ9uV8XidbmBva3wi5jCHqotiaTL3MYjYfd8CT89B9Sti8PBxZuJ8j3 chSlxH2u0eoWRUNZ2Y0RYQ0JMofbAjDW7gIAhUYc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dinghao Liu , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 083/247] media: em28xx: Fix use-after-free in em28xx_alloc_urbs Date: Mon, 1 Mar 2021 17:11:43 +0100 Message-Id: <20210301161035.739288026@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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: Dinghao Liu [ Upstream commit a26efd1961a18b91ae4cd2e433adbcf865b40fa3 ] When kzalloc() fails, em28xx_uninit_usb_xfer() will free usb_bufs->buf and set it to NULL. Thus the later access to usb_bufs->buf[i] will lead to null pointer dereference. Also the kfree(usb_bufs->buf) after that is redundant. Fixes: d571b592c6206 ("media: em28xx: don't use coherent buffer for DMA transfers") Signed-off-by: Dinghao Liu Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/em28xx/em28xx-core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index 69445c8e38e28..d0f95a5cb4d23 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -955,14 +955,10 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk, usb_bufs->buf[i] = kzalloc(sb_size, GFP_KERNEL); if (!usb_bufs->buf[i]) { - em28xx_uninit_usb_xfer(dev, mode); - for (i--; i >= 0; i--) kfree(usb_bufs->buf[i]); - kfree(usb_bufs->buf); - usb_bufs->buf = NULL; - + em28xx_uninit_usb_xfer(dev, mode); return -ENOMEM; } -- 2.27.0