Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp601377ybg; Sun, 26 Jul 2020 15:09:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7j2MhjQIcH/Q2B4trpTp8Hz2MBq2/UEclXF75NJtw4A7/S+rMtMVIzZB9EZU7Kpn+APK1 X-Received: by 2002:a17:906:bcf3:: with SMTP id op19mr713891ejb.1.1595801348764; Sun, 26 Jul 2020 15:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595801348; cv=none; d=google.com; s=arc-20160816; b=U+EhlOCEhaoPC2JadUbi7itRREFw+rhgPDY8SbG9OaCTz+DcjM93sGU+cn1G3BtmoY j4tczbsHAWoHy0oc+SQ3a3ZQAmU55Lu5+mTOQdFqKP2er3KnqckH1aIZbp0R0F5ffkvt 40blZ4GYLJjuA4oogp0Vy0w2Xkg2WzEWalrrUivs31Bc11kXQuVnY8tc6sTTELz/ozlh Uu3GHqnWvgFArS1+zNKuHLKRzVJ5w6UvRB0eriNAtLf7v1LXeplYI8Yfj1KWCz27CagS xgfexYxI/aC5zdi+lswt0h11wITAtuczuSZIU2FhKydBaXuZNgUhiPw6EbTi2PuuKdkc OAEQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+IzmjsuAtBmpLPphNE+utP0izhzv97da99bo9QPRTa8=; b=J3jvNX/+eeoOmUwbA9p/CVmj4BXxFFQwGTtUBvSAteuC5yJUuzPuU/OxZhj9HyuGn1 jqGGLOn5KJfLH6umFZdPAw7JPe2exLM/UxGx0oHBslLIoiVLJqJ5toN/P4HzgGxFSBJ/ cqfANh+cjq+p1f0isXrCGiUou/3oRoH+kbEqyjyuXsBx8S7RvEJnZvmnP/ByUIddqh0R PEkPmSUKgVpwwIjgxAthWDT+G86Vrp3Jwhy3kD5pnCFt5zOcR11YbrBhPQcXok99T4Tw VrZc8IgjBBRZuU7F4wJTX6iw2eNqYLqVp6hzXjuhcWCZeYJAaqhT1qIu7k31qWNQkRT1 Gdpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s3rUecFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr3si4657664ejb.525.2020.07.26.15.08.47; Sun, 26 Jul 2020 15:09:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s3rUecFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbgGZWIL (ORCPT + 99 others); Sun, 26 Jul 2020 18:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgGZWIL (ORCPT ); Sun, 26 Jul 2020 18:08:11 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDEFC0619D2; Sun, 26 Jul 2020 15:08:10 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id o22so10647738qtt.13; Sun, 26 Jul 2020 15:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+IzmjsuAtBmpLPphNE+utP0izhzv97da99bo9QPRTa8=; b=s3rUecFptAUZaHB3Xk+eloq3DPiKZHLpXt+olhKQJ7TAmIcaIjh7cVY+JTy5N2Fvu0 /HxuTGCJ/tAC+1eOawjIKV6SFsoN5j007Kn1m6ENLuetD/PX+2sn4isHYGSnA/U/XFmZ +6AW71YqE8aMeDRaDoAr/mumK6omYAwIuL4uIPc2a5uFg/oppGXZnMkTnwyNgxeszCkx F8EYzKZldSs3Svnp1YIyDslppkXb1c0vpFCy2V9tjACfQjDRr/NJh0kYzvy3k3vOOX69 mSxDi9j9sJ8vSpdrz9lpRy6dVJG663W4TAKMU63NNiPdcTDvPOWnijKwk2vRSfW7ndaG gS5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+IzmjsuAtBmpLPphNE+utP0izhzv97da99bo9QPRTa8=; b=IHvbZRNVOpXXNfb6E5f4MCYsbJVJFPk+b8c+s3eN72azINyXzCdCyL2fHCfKUNb5gs eNw3EB03GBlZFg+7M1LNlolIaZ0ju87z8Ya7tGUxlxfWHxa9b5A76MVtArUlLp3X3q82 oD6TnBKMRyVRYvdN0h/YbLlK4IGnvdO9zX/c0J/t8OPbIdtAICFTpxoHFw4M/gH4HRJO mecl2XA2jmoGv5TNO1IEnhipBFEMG9Pcol05mzW/4GyG+mv0zAEq27qIYYFcqkSIE2gG 7wrEeoN8CLIjM/NVJ1Lv/ZMnLvMxozgB56CMVUmv5zSOgWBcf0jY70zwPZIEpj0PwJhR 6pTg== X-Gm-Message-State: AOAM530CH2m56NBRsWga9xvE5KsDi1XE+Q81Dx24rdOW5i40EhV994W4 SwQSYjCUQWAuDaHIo0Wl+A== X-Received: by 2002:ac8:6992:: with SMTP id o18mr9704010qtq.277.1595801290142; Sun, 26 Jul 2020 15:08:10 -0700 (PDT) Received: from localhost.localdomain ([209.94.141.207]) by smtp.gmail.com with ESMTPSA id f31sm9561215qte.35.2020.07.26.15.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 15:08:09 -0700 (PDT) From: Peilin Ye To: Mauro Carvalho Chehab Cc: Peilin Ye , Greg Kroah-Hartman , syzkaller-bugs@googlegroups.com, Hans Verkuil , Sakari Ailus , Arnd Bergmann , Laurent Pinchart , Vandana BN , Ezequiel Garcia , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Linux-kernel-mentees] [PATCH v2] media/v4l2-core: Fix kernel-infoleak in video_put_user() Date: Sun, 26 Jul 2020 18:05:57 -0400 Message-Id: <20200726220557.102300-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200726164439.48973-1-yepeilin.cs@gmail.com> References: <20200726164439.48973-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org video_put_user() is copying uninitialized stack memory to userspace. Fix it by initializing `ev32` and `vb32` using memset(). Reported-and-tested-by: syzbot+79d751604cb6f29fbf59@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=79d751604cb6f29fbf59 Signed-off-by: Peilin Ye --- Change in v2: - Do the same thing for `case VIDIOC_DQEVENT_TIME32`. drivers/media/v4l2-core/v4l2-ioctl.c | 50 +++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index a556880f225a..e3a25ea913ac 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -3189,14 +3189,16 @@ static int video_put_user(void __user *arg, void *parg, unsigned int cmd) #ifdef CONFIG_COMPAT_32BIT_TIME case VIDIOC_DQEVENT_TIME32: { struct v4l2_event *ev = parg; - struct v4l2_event_time32 ev32 = { - .type = ev->type, - .pending = ev->pending, - .sequence = ev->sequence, - .timestamp.tv_sec = ev->timestamp.tv_sec, - .timestamp.tv_nsec = ev->timestamp.tv_nsec, - .id = ev->id, - }; + struct v4l2_event_time32 ev32; + + memset(&ev32, 0, sizeof(ev32)); + + ev32.type = ev->type; + ev32.pending = ev->pending; + ev32.sequence = ev->sequence; + ev32.timestamp.tv_sec = ev->timestamp.tv_sec; + ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec; + ev32.id = ev->id; memcpy(&ev32.u, &ev->u, sizeof(ev->u)); memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); @@ -3210,21 +3212,23 @@ static int video_put_user(void __user *arg, void *parg, unsigned int cmd) case VIDIOC_DQBUF_TIME32: case VIDIOC_PREPARE_BUF_TIME32: { struct v4l2_buffer *vb = parg; - struct v4l2_buffer_time32 vb32 = { - .index = vb->index, - .type = vb->type, - .bytesused = vb->bytesused, - .flags = vb->flags, - .field = vb->field, - .timestamp.tv_sec = vb->timestamp.tv_sec, - .timestamp.tv_usec = vb->timestamp.tv_usec, - .timecode = vb->timecode, - .sequence = vb->sequence, - .memory = vb->memory, - .m.userptr = vb->m.userptr, - .length = vb->length, - .request_fd = vb->request_fd, - }; + struct v4l2_buffer_time32 vb32; + + memset(&vb32, 0, sizeof(vb32)); + + vb32.index = vb->index; + vb32.type = vb->type; + vb32.bytesused = vb->bytesused; + vb32.flags = vb->flags; + vb32.field = vb->field; + vb32.timestamp.tv_sec = vb->timestamp.tv_sec; + vb32.timestamp.tv_usec = vb->timestamp.tv_usec; + vb32.timecode = vb->timecode; + vb32.sequence = vb->sequence; + vb32.memory = vb->memory; + vb32.m.userptr = vb->m.userptr; + vb32.length = vb->length; + vb32.request_fd = vb->request_fd; if (copy_to_user(arg, &vb32, sizeof(vb32))) return -EFAULT; -- 2.25.1