From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4955BC10F14 for ; Thu, 3 Oct 2019 17:38:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E92C20865 for ; Thu, 3 Oct 2019 17:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570124330; bh=D7YyxjKijRZ/TheVnJWsZBt5yFo5UywORh7hk3Psqe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yMyT/AmnRJb4/t6ckzkFw6WQLvDXHh6OYrtCFBzBj2L1PY/QljoxbWqZcKckB2WGQ RPh8NKdJVBjmTfAwAbAVKQJp4/x0AGOawqic9A+YKIn/CChoFWqfv9pWL7zHv03c/a IXRcLJxSB7V1vISWypeEUvQZLsZK3f+hK1qZ45wA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730476AbfJCRip (ORCPT ); Thu, 3 Oct 2019 13:38:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730052AbfJCQCP (ORCPT ); Thu, 3 Oct 2019 12:02: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 1C16520700; Thu, 3 Oct 2019 16:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570118534; bh=D7YyxjKijRZ/TheVnJWsZBt5yFo5UywORh7hk3Psqe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ueEIWaIR2iF/Diqi8ESQo3NLcsP1QZS7w3GJp+6oone46SqFzS3hwVcAEMWtJMOnA uPdKZH821mqL9ZnwvzJ58pkTp5LVlx8wbk75xNuMBj3ObpUc8xK35r2Tpmay2yLhAK lFlrxdJC7MyVRk0b2Dix7LPZHExFgXnu2P2NUNrs= 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 4.9 046/129] media: hdpvr: Add device num check and handling Date: Thu, 3 Oct 2019 17:52:49 +0200 Message-Id: <20191003154338.531678370@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154318.081116689@linuxfoundation.org> References: <20191003154318.081116689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 a20b60ac66ca4..7b34108f6587e 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -278,6 +278,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 */ @@ -382,8 +383,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