Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp947794ybi; Wed, 17 Jul 2019 07:20:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2e6FT1kLsSKPHI7AFMwUDchYwJnC+EdPbP40nEP1IlhwZLct6DeFI6SUuOFLI+79zFHwz X-Received: by 2002:a17:90a:c596:: with SMTP id l22mr6366071pjt.46.1563373249446; Wed, 17 Jul 2019 07:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563373249; cv=none; d=google.com; s=arc-20160816; b=i4ZG5kbpzQGSvjtnCUpfYaWBPzF8lFSc32+vA+tsCH5IKvQ7nkM3a0k6cGYs4lFBdm Qf/VyzMTmIhTS1dzLoOCNTHPYXZNbwYb7P5S9qi3L22BMa0P2SiS29Xy30+N9gYTdIj8 KCE9cAL6/YKJmf1NDhO2B6Q0bTMnRU5nalbhAq7ayMJE7dysHRhve1IUFMRikhLQX93i KRjbRyNOwcamVcX93TrQGpdmophjxmKe3Q1exvocM/ctNHfSFaOnb1SNLiHHMxWYxTSX U4ExvBHCUjYJ1AQpC25ladF0CDbAOnifbl7TrBdwQduJRWpWxCfZooVwPWPxgEIEob+6 9c4w== 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 :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to:dkim-signature; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=iyalo7Ttfj5h3p3RvlS94x96rXyvURW1dInDurLkSqUJv6sByrAIeZ0Gv2vYbgnCDF WxiLtFFKYjxx8TKJAW86eZ3ioEWqtQFxdEpXQCxSeojJouwCJe2MsPoJOTb/Km2DqXzL MpDUyknllHpP+V0NKEcNfTxaGIb2QjA4CRt9cUmcY+SY1u6R70GnCkLMyv3P+718xJZ/ NkES1aVlVwab4Hd+p4SskX+FlOKB6y6ydsq3GLhPhpRfjo9cD/8/v9mcZAYsXowbMK7l BTpLMOzzm4mMbstmItQ26CMYOCgoqa0Sg3F5uxVHvVjpVwKEG0SGypyxW2bZ8CvTglQQ RetA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=GbAckFZo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ucsd.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q195si22918326pgq.119.2019.07.17.07.20.32; Wed, 17 Jul 2019 07:20:49 -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=@eng.ucsd.edu header.s=google header.b=GbAckFZo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ucsd.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727675AbfGQOTu (ORCPT + 99 others); Wed, 17 Jul 2019 10:19:50 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39395 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbfGQOTt (ORCPT ); Wed, 17 Jul 2019 10:19:49 -0400 Received: by mail-lj1-f194.google.com with SMTP id v18so23791041ljh.6 for ; Wed, 17 Jul 2019 07:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=GbAckFZo8/FhS/sr0TgjOzcalYCkcrFtP/AfWtc1bYXaMcwMOhHoBYlG+eYqMNRKXF EARfkktXu8aBMkttzbAGOJy1LM8bVJX1FK40HivMaxhUz+zRbo4WdGN+OAXNFTjMCKkr S8FsublwaWgzchrOJhjHU4uJ7Fzuo5dSJTRug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=bvx6sZR+KLHi8tG55qi381AVexWWoaaENNJORNxNqzxTTZNUyw5L4Zrd64CN6RTD+Z kUcRD6ZOFvqCw72v9yCU3FZ6d7Fet72CBoL1pSeUi5U4wyPI/OG1sQQc3PJtf4uLz7+0 F0/1NbUHomQOZmcs5yfpeyE6McaGb/jYkmQa4JX78nz2b0333HoX4mqxEg0hMYg+VlRK pN1O+X6vDXfSO4VMFc+A5OuaWEPU9Seiec7LcB7uDuRFPPmSPGFcjlW9UPO/DEY+coxi 039QQJiaXM8XPPJPqeWh3eJqfO2nQSt8fkcPAd0LUD2hh6XJ899bDVptFDvs5e2zJJAL uQ6Q== X-Gm-Message-State: APjAAAW/tmjXHvZvjGmjYInpkf9BXyE62hFdtxPf6EN6CaaTdHnbif24 o6SKBQImOMv0HjVddDrW5fNXqA== X-Received: by 2002:a2e:8756:: with SMTP id q22mr21364419ljj.108.1563373187770; Wed, 17 Jul 2019 07:19:47 -0700 (PDT) Received: from [192.168.1.2] (178-37-168-43.adsl.inetia.pl. [178.37.168.43]) by smtp.gmail.com with ESMTPSA id d3sm3472935lfb.92.2019.07.17.07.19.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2019 07:19:47 -0700 (PDT) To: Hans Verkuil Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org From: Luke Nowakowski-Krijger Subject: [PATCH RESEND] media: hdpvr: Add device num check and handling Message-ID: <757f11e5-8463-4f48-1f42-1ecf9bd0a86e@eng.ucsd.edu> Date: Wed, 17 Jul 2019 07:19:46 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in V1: + add storing of incremented index in dev_num var + add bounds check on dev_num and appropriate error handling - remove attomic_inc_return from inside of hdpvr_register call drivers/media/usb/hdpvr/hdpvr-core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c index 29ac7fc5b039..640ef83b57c9 100644 --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -275,6 +275,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 */ @@ -371,9 +372,18 @@ static int hdpvr_probe(struct usb_interface *interface, goto reg_fail; } #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