Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8379781ybl; Thu, 16 Jan 2020 15:42:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwoNKQpEHSSIK8v1qJLd7d7/0I+VRwWYtqYM7OJcDA3+qYPnI5wcsNUgVKRF06e/non5tAc X-Received: by 2002:a05:6808:611:: with SMTP id y17mr1339648oih.146.1579218133198; Thu, 16 Jan 2020 15:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579218133; cv=none; d=google.com; s=arc-20160816; b=G/d6E4/LvdOjf/C8h5kEOPPMWuuErPEXQ2D0FgenWG3pAXpUAen2AJBhdhcgwoZ0Jd b6z/jAoFs2C/IyI5gWDsZUIugD3IIgmuTf2nnRbRnU8xQtK6Ke/BpVssq8M5TUocGFEi Fvk498SUfjwyG7Ukm1egrI7AZsWGN0s1AiWsyxKekzxNrzMyIzqJDQL3g/5RztwArJ2F y5QubnWDNgRVJapdJojEj3p7nowk4SsKBm7HpNLv7QVPpfQ5YUA8ICLCha13GZgKzeGz 3nb3HwuwF/YDAXxzwN0WvCFkw/Zte+kpJlHUK2Ur9LTTxaZk7woCWJhJMdyP48JKNpMd 5zIw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HY681ePAIPKKPw/5HCXWFoUfuI9UfCo1Yx0ib7eL5+o=; b=VLvvBjTnUu3yxL65lYNUFJuUzfBUvAdEDSWHH2leMWKfEm0p57usUyx7mLYGZEdv7n nA39rEM4bYj8aXyunDLiQxTIItSf+keqqtzJt+wzymkcrT+oeD2FqQblYpvedr6QeCZd qe+52B/CgREamay7iR+CRsMWp53XU+BMM6Vx20a+ORsQG7FDYQ0zjrb93j3yIq+EosYG hJUD2JRAuVzTsV/NwDeGV+qlj8bMVcfoRNS4ibz1yb4LJpp/zLUIDvL2RBm5+lJux9Y/ 3cZt8b/3LjhZHmjzgekHhWCEFGdbyyt80I2IDnwF9dsTsmmGqg6vTo8WMiKUVkcJbmSt 2rgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e+3uC6EA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si14629075otr.223.2020.01.16.15.41.57; Thu, 16 Jan 2020 15:42:13 -0800 (PST) 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=@kernel.org header.s=default header.b=e+3uC6EA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387703AbgAPX1p (ORCPT + 99 others); Thu, 16 Jan 2020 18:27:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:59740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390323AbgAPX1n (ORCPT ); Thu, 16 Jan 2020 18:27:43 -0500 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 041F2206D9; Thu, 16 Jan 2020 23:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579217262; bh=M11YPmtxsmk+XesG8cp2Yxwo/AKLCEUpp6AZOst0NJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+3uC6EAgy+jaOHffz9YeuFi0J5kaZ9N1jaKA0bpaOo39NSHb1g/BesSsek+4aNrO 6pmGKK5ExMi+ziotle/tscMTo+rpuM9Yy9EK8ARhKPAKdt8N1DQUx8QMvx899DGUgk d2/poHd0Sr7z2b9/OS4Isqht+qSG+dUhuF0Tdnvg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+66010012fd4c531a1a96@syzkaller.appspotmail.com, Vandana BN , Hans Verkuil , Mauro Carvalho Chehab , Ben Hutchings Subject: [PATCH 4.19 11/84] media: usb:zr364xx:Fix KASAN:null-ptr-deref Read in zr364xx_vidioc_querycap Date: Fri, 17 Jan 2020 00:17:45 +0100 Message-Id: <20200116231714.921855815@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231713.087649517@linuxfoundation.org> References: <20200116231713.087649517@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vandana BN commit 5d2e73a5f80a5b5aff3caf1ec6d39b5b3f54b26e upstream. SyzKaller hit the null pointer deref while reading from uninitialized udev->product in zr364xx_vidioc_querycap(). ================================================================== BUG: KASAN: null-ptr-deref in read_word_at_a_time+0xe/0x20 include/linux/compiler.h:274 Read of size 1 at addr 0000000000000000 by task v4l_id/5287 CPU: 1 PID: 5287 Comm: v4l_id Not tainted 5.1.0-rc3-319004-g43151d6 #6 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xe8/0x16e lib/dump_stack.c:113 kasan_report.cold+0x5/0x3c mm/kasan/report.c:321 read_word_at_a_time+0xe/0x20 include/linux/compiler.h:274 strscpy+0x8a/0x280 lib/string.c:207 zr364xx_vidioc_querycap+0xb5/0x210 drivers/media/usb/zr364xx/zr364xx.c:706 v4l_querycap+0x12b/0x340 drivers/media/v4l2-core/v4l2-ioctl.c:1062 __video_do_ioctl+0x5bb/0xb40 drivers/media/v4l2-core/v4l2-ioctl.c:2874 video_usercopy+0x44e/0xf00 drivers/media/v4l2-core/v4l2-ioctl.c:3056 v4l2_ioctl+0x14e/0x1a0 drivers/media/v4l2-core/v4l2-dev.c:364 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:509 [inline] do_vfs_ioctl+0xced/0x12f0 fs/ioctl.c:696 ksys_ioctl+0xa0/0xc0 fs/ioctl.c:713 __do_sys_ioctl fs/ioctl.c:720 [inline] __se_sys_ioctl fs/ioctl.c:718 [inline] __x64_sys_ioctl+0x74/0xb0 fs/ioctl.c:718 do_syscall_64+0xcf/0x4f0 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7f3b56d8b347 Code: 90 90 90 48 8b 05 f1 fa 2a 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 90 90 90 90 90 90 90 90 90 90 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d c1 fa 2a 00 31 d2 48 29 c2 64 RSP: 002b:00007ffe005d5d68 EFLAGS: 00000202 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f3b56d8b347 RDX: 00007ffe005d5d70 RSI: 0000000080685600 RDI: 0000000000000003 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000400884 R13: 00007ffe005d5ec0 R14: 0000000000000000 R15: 0000000000000000 ================================================================== For this device udev->product is not initialized and accessing it causes a NULL pointer deref. The fix is to check for NULL before strscpy() and copy empty string, if product is NULL Reported-by: syzbot+66010012fd4c531a1a96@syzkaller.appspotmail.com Signed-off-by: Vandana BN Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab [bwh: Backported to 4.19: This function uses strlcpy() instead of strscpy()] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/zr364xx/zr364xx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/media/usb/zr364xx/zr364xx.c +++ b/drivers/media/usb/zr364xx/zr364xx.c @@ -703,7 +703,8 @@ static int zr364xx_vidioc_querycap(struc struct zr364xx_camera *cam = video_drvdata(file); strlcpy(cap->driver, DRIVER_DESC, sizeof(cap->driver)); - strlcpy(cap->card, cam->udev->product, sizeof(cap->card)); + if (cam->udev->product) + strlcpy(cap->card, cam->udev->product, sizeof(cap->card)); strlcpy(cap->bus_info, dev_name(&cam->udev->dev), sizeof(cap->bus_info)); cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |