Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4306753ybi; Sat, 6 Jul 2019 02:24:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxu1P0ZOlHVMR6kiM0URNItJaTyTqKN1uknA6uNB2w+WvklCKk3datapUdSXEhmNnOKBQB X-Received: by 2002:a17:90a:c68c:: with SMTP id n12mr3271654pjt.33.1562405081666; Sat, 06 Jul 2019 02:24:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562405081; cv=none; d=google.com; s=arc-20160816; b=tGxVJwRoO4VsCnaiyCycBfThqtJRJMgyJjcxLRK9wJsriRZLqJcwqEAXhBuoS0RHHp u1/sd3bvQRzOIPbnL3LkVX2qrsLyVZOnbeNJbXKI542fylQVphMV7ktuaOb7jQAqsnn2 YDflY0xTHf5jIQah6te/0p2RpB/n+1DDgppttmyg2TYZBplJ8W+EM8QlbKOVxsr3lM2j vtZSCkrO6orqdHK3s1o8UaC6OpNwzc9MsjsAkszCtPR3x4WCrXkFbsPAfR305yMI/ayr mBbgovSsN37eH70R1VPYmt16E6rTfjFTFyE1MAHNK7PBzdcpKqeuJvlK+3aQyY4/42jf r6kw== 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=OQnjapcKNfySWl8myMP5QrzCnMgABQ3QMgCmNrKNrv9lJ7F3o6E9xoHLwSgvn9aQm3 74YQTylq6K9W8Rk7qKCp+yikbc1HGzppuDPWDN+ITKG4OwmjL32FMBOT4fviCb9fdtEV hptD4Iw0IkuFU2Sp7uNyWPRUq4Qvok4MrSsDSx6yoaiomA/XUeQOd4eIXjiicsivLBqe YBIy0NUXoMn7WT2cKLsk6WCwWNKgXUuhuczg2ChPVsrnIka1bD3J9Qxndo+XJiYt2xN6 F4MzECy+cZTrdNRVDKbyPIut292OCi2PYCGEQGgVALD3VV95KGTyMbP+XufkpOLmE6qJ jFOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=dg+5O6A3; 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 d18si11854783pfn.202.2019.07.06.02.24.16; Sat, 06 Jul 2019 02:24:41 -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=dg+5O6A3; 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 S1726016AbfGFJXt (ORCPT + 99 others); Sat, 6 Jul 2019 05:23:49 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33030 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfGFJXt (ORCPT ); Sat, 6 Jul 2019 05:23:49 -0400 Received: by mail-lj1-f196.google.com with SMTP id h10so11387891ljg.0 for ; Sat, 06 Jul 2019 02:23:47 -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=dg+5O6A3uPa8xOtRcfFX0oHBjZZWZV5meMagQazqVO4+KShJachCtOw9uhwUsdM5LM KEYjIyZskOEqbXsRqnT1N4mdlT4aFScBIFJQH7WYEl/LJMAvvunpegz9vo/mbpjsUeDO VXvw3VKSj/qH3kKUOmNJIuwxsgk+QRg9tia5k= 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=Mnkz8Og0/SH68GKhdNv2odv7nDMmMfuF/4ZpgpmoMezd/W12X+jxn60Q4dlDPya6Uh bINbeBrU35mljL0qWeVgm5VROCqeTCaXeoN8jW80A9I6GPf2KVV6jeWyw+1ZZPKZYHDu The4OrAZtdkQB58YVfGDHfQaDcJ671/cjWFm9WgxICZCqBSSgVmCATTqgeiZb4aiC7JQ W8zhmELDCry6eN9dj+ZlArTa50mlFWst0hSTcYKGGFLA2euorDq7E06pcbEX2RLA0NtL 5uw6Nz3kr76dEc6VEQ9H4G+cyq72FsF5uy8+ezrIa0Wf3bUBcDY6pFb+xst1PHp5SqMe bCsQ== X-Gm-Message-State: APjAAAUKfqho/s3OItmQR+fJB2Kk2WX6s5F1q+S/0I+VVvv3D18/6Tw+ +TVh8YCyfrcbXfliW6GgfTmW0w== X-Received: by 2002:a2e:894a:: with SMTP id b10mr3893454ljk.99.1562405026913; Sat, 06 Jul 2019 02:23:46 -0700 (PDT) Received: from luke-XPS-13 (77-255-206-190.adsl.inetia.pl. [77.255.206.190]) by smtp.gmail.com with ESMTPSA id 137sm2278544ljj.46.2019.07.06.02.23.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 06 Jul 2019 02:23:46 -0700 (PDT) Date: Sat, 6 Jul 2019 02:23:43 -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: [PATCH RESEND] media: hdpvr: Add device num check and handling Message-ID: <20190706092343.GA5462@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