Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp582091iog; Mon, 13 Jun 2022 08:33:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u79nZHJceWyZOVteVbLglkQrcElZARfippx4Ecxzh+qBEfN4F5YeVk9W+nT726o8mAjm5A X-Received: by 2002:a17:902:e54c:b0:167:4f35:9556 with SMTP id n12-20020a170902e54c00b001674f359556mr348804plf.5.1655134399400; Mon, 13 Jun 2022 08:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134399; cv=none; d=google.com; s=arc-20160816; b=YsQOuxpt0186kNT+t77mkhTbt987xVMUgNrkcYacu6PQQAW3kIn+6q5oGBg3/HwHRM r78UoYknF/7fveslc98vwl4TzNZs8O4MjBlGlIc24RivobmtBzbtRQCCG4qozed1Vg5R YDsLf7TdRnCJy8QXzOiaSsDLP77ZHbjMCvzrBzQopLcOcNuYe8O/A5AmZS0HQdjy3AD/ 88CYBh7HzeUo7dU/3cs4IwSdHqJLxBIX5ICkwjsO+qeeJmkhfjxjxRkvZClNif1+8DvD HrEpOkDJLF0NqZeWvJd83AvrjYQUIShVFY8whSPF3gncIgsKOczKICb/FedR+FsBg3zi LZrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PewFV8Whw9QIA9eP2DFSwfiBnsm0r9ZeL1a1CnzFjnc=; b=ydAwoUOhmSzdt1QctiFzgvaWMUh2GF09Kk+IX72HUVC7QC4JjAiyQWISpGcsZmzzoD /d60QOvSURcw5FFY8tUnVpn9WMYuEU/yo8tscK3zeZlDjF9bZSfq9RjuWrRYZzWTuWbm P28xlSFke0cyXOnmuMqnRtLhz/GiZcpZENrCrcZir+q3HAraaHSXJfa8pBzS7CgzC0Qd 5WvwQg5pIgxLmYVyogWlCd/h25fP1GVFKSF6jbR8xBMCAbchi9p+SZR+RVDVBSsWABpc 4ddXeHr6Kb306qpUQ3l+Rv2m7oZV8g+FHpA0R3pcAzfEr+V9JLK/TustuEwikwxEeIlR j+mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f879aRqK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z21-20020a637e15000000b003fe28119604si8399548pgc.270.2022.06.13.08.33.07; Mon, 13 Jun 2022 08:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f879aRqK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242274AbiFMKTS (ORCPT + 99 others); Mon, 13 Jun 2022 06:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242226AbiFMKSR (ORCPT ); Mon, 13 Jun 2022 06:18:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED29DEE1; Mon, 13 Jun 2022 03:16:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 44A42CE1106; Mon, 13 Jun 2022 10:16:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C8FAC34114; Mon, 13 Jun 2022 10:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115360; bh=iwcLEnCp0fL7LuPfkZtKxJoSjexjiy8MEQUq2/JTD04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f879aRqKDYJIgKFeq+AVegR7ZF6DW73PrvZpYrN2XbYKiqzgR00SbuNWK0AjghTL3 wUAOaQkij03vBh+j9UIcJrY8LsyMpPk+UYf29qIaxWdXaAs0HZIpuH+/8M6ICiZ/5J KCwRlvOoUdP98/oQi9rhPSoFLu35Eiw/nm6JaFao= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , syzbot+1a247e36149ffd709a9b@syzkaller.appspotmail.com Subject: [PATCH 4.9 056/167] media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init Date: Mon, 13 Jun 2022 12:08:50 +0200 Message-Id: <20220613094854.055228131@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094840.720778945@linuxfoundation.org> References: <20220613094840.720778945@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 471bec68457aaf981add77b4f590d65dd7da1059 ] Syzbot reported that -1 is used as array index. The problem was in missing validation check. hdw->unit_number is initialized with -1 and then if init table walk fails this value remains unchanged. Since code blindly uses this member for array indexing adding sanity check is the easiest fix for that. hdw->workpoll initialization moved upper to prevent warning in __flush_work. Reported-and-tested-by: syzbot+1a247e36149ffd709a9b@syzkaller.appspotmail.com Fixes: d855497edbfb ("V4L/DVB (4228a): pvrusb2 to kernel 2.6.18") Signed-off-by: Pavel Skripkin Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c index 40535db585a0..b868a77a048c 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c @@ -2615,6 +2615,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, } while (0); mutex_unlock(&pvr2_unit_mtx); + INIT_WORK(&hdw->workpoll, pvr2_hdw_worker_poll); + + if (hdw->unit_number == -1) + goto fail; + cnt1 = 0; cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2"); cnt1 += cnt2; @@ -2626,8 +2631,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, if (cnt1 >= sizeof(hdw->name)) cnt1 = sizeof(hdw->name)-1; hdw->name[cnt1] = 0; - INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); - pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", hdw->unit_number,hdw->name); -- 2.35.1