Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp71317ybp; Thu, 3 Oct 2019 10:18:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1QHdCWWcHj2sGH/8gkOwqyQtxeJED+cKS+JNqfHAyVpvpsZjlnsHdqJOb44guI+MwpQph X-Received: by 2002:a50:f616:: with SMTP id c22mr10486702edn.235.1570123138396; Thu, 03 Oct 2019 10:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123138; cv=none; d=google.com; s=arc-20160816; b=xnmnxPyQLvVa0tXNFyHeXIVzVd7lcuVQznB7oUbQd5w3d/qsZfSIoCywwS2pOUvd16 QujCkM4f+3HzUyO2XegyRX+7VLM338suBcnLNENcLyKcCWqOVeiQincoT3LUpTJP+4J+ NhpefOfwIKv8NTQqoNmtwv1S2FRLoQW9K2EEPVtc7n3VYxqNEfbu82VMdIkuAZf5+emX mJD4IBGpunULnTkdxrIuHwdxzpOPEnFeu4onCyDS+y96BiR5pajTzpMJNPCRPskBiQlK JVD9WgyjvZihw570B6nqeeboWP1ERGBPuG8NKY1eg+17uoj8kyMApUU5SJbs8eFWXanr a/mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0dK5fX5B9fmWj2CZu/w7vV+EdQIofBn7lkpVtvzi6eU=; b=0q/h55N64BV81g4KYALkpOxIxfAfrlkguI8z+PWNr3bdyzbY/EFo5Y6I656wRmAKqg sZvyAbiZmK5tDNCi63ETMusL1jTGy49VRhqrCc9rSZfxpWeHXcZZzH9B9wvQ9/aEeO5e wjrGrN6EvXm3k6lTJ1rihI2ekKgLM0BYriSjlaKObKZIKWy5WMtEOkoBt1CJFWcfgmX9 NXxWGY5QC6IwU4ZC05uwVV0dD8nWC7Q/kJKNIMngBgLCu1JYHkwc39CdM3JoDe6g6jtx 1Lb63WNPJ2oOxLp+HetGg6SdWPt+myxPXBbWyQIXuoxJ1Im048oU2ANBBVjVKR+0cUOP Tp1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cLqeM+g1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f20si1716103edm.365.2019.10.03.10.18.34; Thu, 03 Oct 2019 10:18:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cLqeM+g1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390280AbfJCQ0X (ORCPT + 99 others); Thu, 3 Oct 2019 12:26:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391006AbfJCQ0P (ORCPT ); Thu, 3 Oct 2019 12:26:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E5B62133F; Thu, 3 Oct 2019 16:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119974; bh=u/cx5Fx7ocHi7GpON+az0NLHqlFEw3vSZrk3Gb0TNFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cLqeM+g19IlSngVmYO8KF5bJRdTuNP/6W8ACfJSOBnou60DOe309M8tyxNegeh3sk rSh9b6/2Le1RZHA3l/n841bdwF9a7S8GtIUdDZ2fOl5iZCHJiJ/jBKz6dJ7mdZZUbB fXBOEAwFLLqzZAaWFKmZGktBzr6/avvVLgUnGCPQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luke Nowakowski-Krijger , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , syzbot+aac8d0d7205f112045d2@syzkaller.appspotmail.com Subject: [PATCH 5.2 051/313] media: hdpvr: Add device num check and handling Date: Thu, 3 Oct 2019 17:50:29 +0200 Message-Id: <20191003154538.126270389@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luke Nowakowski-Krijger [ Upstream commit d4a6a9537bc32811486282206ecfb7c53754b74d ] Add hdpvr device num check and error handling We need to increment the device count atomically before we checkout a device to make sure that we do not reach the max count, otherwise we get out-of-bounds errors as reported by syzbot. Reported-and-tested-by: syzbot+aac8d0d7205f112045d2@syzkaller.appspotmail.com Signed-off-by: Luke Nowakowski-Krijger Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/hdpvr/hdpvr-core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c index 9b9d894d29bcb..a0905c81d2cb2 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -271,6 +271,7 @@ static int hdpvr_probe(struct usb_interface *interface, #endif size_t buffer_size; int i; + int dev_num; int retval = -ENOMEM; /* allocate memory for our device state and initialize it */ @@ -368,8 +369,17 @@ static int hdpvr_probe(struct usb_interface *interface, } #endif + dev_num = atomic_inc_return(&dev_nr); + if (dev_num >= HDPVR_MAX) { + v4l2_err(&dev->v4l2_dev, + "max device number reached, device register failed\n"); + atomic_dec(&dev_nr); + retval = -ENODEV; + goto reg_fail; + } + retval = hdpvr_register_videodev(dev, &interface->dev, - video_nr[atomic_inc_return(&dev_nr)]); + video_nr[dev_num]); if (retval < 0) { v4l2_err(&dev->v4l2_dev, "registering videodev failed\n"); goto reg_fail; -- 2.20.1