Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2223517ybi; Mon, 1 Jul 2019 08:16:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYrh5sh/EyPtluB3TcHrzc1ZUSZN3O5hCI0ttQL1ZxsxYVgsJS8urXQolw7XN7KumydIUh X-Received: by 2002:a17:90a:25af:: with SMTP id k44mr31151405pje.122.1561994216730; Mon, 01 Jul 2019 08:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561994216; cv=none; d=google.com; s=arc-20160816; b=yrFlLzSSgm7UbwkNLMlK4D4yOUGFjcwu2P3UclxrYTT+KEeWJs9LUdthqNg5ilmxw+ dSmpPOOQVbKoZmeLj3KTGicHju4xPbZ4LJu9T0joID+SPL7rJqZ5b2mb3bqFZPixFBxH lZU/BAQQUwBcobhhrlMM1Ns/7z5tiNkO1l2FLZeIYJMSELZ8PZUJhTFUg/lcIo56YYeA 27u7cJeDwnL4fI/uCPRHhLg+993eajFt49wTi7Ka/cQGml65zCeZ9FtGvEENhENH/bKV 5I7ZdxH1nBlrofp7KPs2rqE0BIK8tu4YQIxSSbnLXqOSV+UWoKTbycwcmkumP+Ftib30 xGtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=EbmKNvgyIAOO0rd5nv2Gac/V/nSB9LMAZF61p4kTZyGURreYnC7PKQYV+SweLbUjDb K99xk5IP3vanGchc3Nvs/kKng089Ljvh8omLo/yJfQgynrnAJQ06A0bqXHC8p7SqbLVf gM6F86dV+lhyyrUHY/XpuECp670ThXipl1v6c92lHvFHhUAvxRMW0A7fJ+WYqI+Wg+Go i4KCFCuTJ9sv7m9DIH2wnYUWFUOyBedryplELSEu8+qLyRyi4p2z20J4izhs/5TsqnAo 9dUrMIe4b6gNUKJdHD9nH405FdPk8X3D65H7shX6jlsN5/NLK05HBXf/3CpuH4ExDv27 lfHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=V1jsTVUF; 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 cf16si630788plb.346.2019.07.01.08.15.38; Mon, 01 Jul 2019 08:16:56 -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=V1jsTVUF; 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 S1728525AbfGANWK (ORCPT + 99 others); Mon, 1 Jul 2019 09:22:10 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:42276 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728155AbfGANWJ (ORCPT ); Mon, 1 Jul 2019 09:22:09 -0400 Received: by mail-qt1-f193.google.com with SMTP id s15so14534072qtk.9 for ; Mon, 01 Jul 2019 06:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=V1jsTVUFpJBvfOluYHWnaCRRrKG/jSwC4bLkNxH+C2kE3lb+YfMwg/P8B6EPXwf/jj nEYkYvg8Fri7MktJ7oLoNgi5BlfUCoWbLOPQRaQqQ0NVP2G0qWPxy5g9wNVL+zIAkpyo icY46H9/oLXHEVI/LU5ek7vbEYvSIWs1vm32c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=ALgZ6/TH1TMMHtthc8F5W9I7v5d4Oi+UuqN4eyBdrw4=; b=F5S+eLHN859P6i/3HM+jvNhp22kypo4VKF6//bTGFU6xu/dw7Ce3RoxEk/kBRMCuWe rjt+Rq5cMS3VZA26Ov+MbLoXtMQ249okrcZUDdHddNS4zpDH0pn4MyJFOUFAVMZTGKcV Vog+h4fF0Qa42veT/rVp+XYtziUonVlZ7MHnhqen35H1y96LN0MUhg7WAySIvaLCXRAc 1leYPOUEmCazEgRzi+SV3pxNgfmh9pdTYlUv/wxLtiPvGmv58fbu9tFxWJxEkakJXO1/ cDt2oRqEMZkMOnPGAogscQ5scJKfo67ld+vd3apNLguxGIvdxKJs27avavm1T72tRPlr IXdg== X-Gm-Message-State: APjAAAUXab5Tpsw3pkLzKdND12so7kDvmZBReZ+TBzygPbG32asqnL93 9fuQ2HP9nShqy8UgvTMX5PtzCQ== X-Received: by 2002:ac8:22ad:: with SMTP id f42mr20508420qta.271.1561987329030; Mon, 01 Jul 2019 06:22:09 -0700 (PDT) Received: from luke-XPS-13 (ool-457dd03d.dyn.optonline.net. [69.125.208.61]) by smtp.gmail.com with ESMTPSA id k40sm5627084qta.50.2019.07.01.06.22.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 06:22:08 -0700 (PDT) Date: Mon, 1 Jul 2019 06:22:06 -0700 From: Luke Nowakowski-Krijger To: hverkuil@xs4all.nl Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees,PATCH] media: hdpvr: Add device num check and handling Message-ID: <20190701132206.GA8193@luke-XPS-13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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