Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp605040ybg; Sun, 26 Jul 2020 15:16:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwllTJInmYdzkUWyZ7YzygtN3pE5cXJRpRUqllShj1fFgns0jEqVZFCWgXAjCuiGZNcoeqo X-Received: by 2002:a17:906:f757:: with SMTP id jp23mr1209911ejb.297.1595801772594; Sun, 26 Jul 2020 15:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595801772; cv=none; d=google.com; s=arc-20160816; b=RzFW3iP6hWWCwPEU1iApNSL6x6wLX2olAf5WIedMdkQQJ6cIPrr2cCSd5wjZAZDvmE taQjEPIzdao6L65NZeYOP2PUCZOh3DMWgziyotnmcnLaO5FcSLv9NrE/Lid462Jiae6I gkjBwFEVxJ1g0vjDdaLQDPIUMBFupBWiRhqNLDK9BG7//0xG7qOVMigtfT7q4mxfsHR8 JnFtfMuvC/dyAugjzUEvmoI6kWR48D+dqabPjVtf5GMIP8n7LmJmQkx2JqzB1TloOi2E cRAdbkQkLi6MY/rzhTDUDK3M0R61K167AkcICK6W9XkZesYDUa5dok/mKxocD4ZG2HcF B/XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lYTK0Cb3cN0oru/eBKA51sHEvh1EM60eDT1VBtlot+Y=; b=Ul6Xig1pkWdPLjWOwa/ULJCgbMU+IIxMfW3JrIwV2CALch34oJ3mZ2+GzYl0muIlxx /AZN5ncA/wdSxSCsvW5JBJ8jnjjzz7SxiDGZXlQfZsDMtIOEiG600+21gXgNZDRDLF7J xXaVLE61WAiymaON7GSfPFErdymIINLIH89O7aFpahu5XXyAVWJTudg/1wUHw5XasWKh alQpqruM7haXHvbc/CPBDCV24XuxMICCzhGW5v76JD3MXMZJwhM5QY7r2WAQDEc0r9FK n20d/8KA8IB5m7KlLjhKHwIqcxBBlFIEWESHuBsnsqOoK6euzes80N/S8h6tE4HXB4hM askQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uWvH6L+K; 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 b18si4478005ejk.572.2020.07.26.15.15.50; Sun, 26 Jul 2020 15:16:12 -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=uWvH6L+K; 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 S1726907AbgGZWPR (ORCPT + 99 others); Sun, 26 Jul 2020 18:15:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726253AbgGZWPQ (ORCPT ); Sun, 26 Jul 2020 18:15:16 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FAB6C0619D2; Sun, 26 Jul 2020 15:15:15 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id g26so13711472qka.3; Sun, 26 Jul 2020 15:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lYTK0Cb3cN0oru/eBKA51sHEvh1EM60eDT1VBtlot+Y=; b=uWvH6L+KGS9WbhlXtAw26c3lrrWVX0uM6pJIfxuh6zZlOcb2hSvT+wkrBX08GocMgl hUh0bd8i83H7nMr3UVc8jJmLFGSaPaUA3TwMSpkciFzj0DhBmU6LmMkzRTE3sFaufpVY NONbpW3sMAqR3y7jPqzdUSF00AzMzZwwJCtsdS/a0q7Xz2+4ucblqMeDi5rTi9iGTg7Y Mg2AIG+IaOkgQwi0BdydES5agtmwi8e/5LyRsq512sci9yZArciKSDduBG1Z0Bb5EPRg znbsjzrMKQDfWocazwvH4n8LDFknJmDNIwsruPCPqsGy6PJ3CW7wiD467C3zY0lkXjVJ LF3A== 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:references :mime-version:content-disposition:in-reply-to; bh=lYTK0Cb3cN0oru/eBKA51sHEvh1EM60eDT1VBtlot+Y=; b=gvqbDN0WyF0pwDMWFoRS71aW7R3zyLBR/bDZwl+c9BnKc3uBhnxUW/A0KdKgvsLJx5 zaT8T/+KgrwoZz5G7KKBENqfV0gGF0bHza5kS1TE4oaud4CXcU3moHQkpRgeZ4yzhpKy Wp7l3QZmUbaW4eohKC8hjrvWTQqwIrYCbcKcPROXXJuEa1rR2rMwKsNKQ1h/sX1ozMYU eYTIBtH9At4zw4HH8R/UyqLjtOwbDC1C5xBry1JcaG78O0W2TWOKhpSOJdNndw2dfuSy /uQqDLR44KnU0emrpIOHjDltD03WoJpkYCTyw2/V62hlKcXKph0L8Gbgx42BKuxEIPdo yqXA== X-Gm-Message-State: AOAM530u6j3EtNuNYupZrew/aoNK6MMGZE8IM2TFz/uUQ1NxtzFHgghg yZ6WZxX1BvyrmMUFT37kXJhnOgwg1g== X-Received: by 2002:a37:d97:: with SMTP id 145mr20136700qkn.218.1595801714732; Sun, 26 Jul 2020 15:15:14 -0700 (PDT) Received: from PWN ([209.94.141.207]) by smtp.gmail.com with ESMTPSA id r48sm11573138qtr.17.2020.07.26.15.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 15:15:14 -0700 (PDT) Date: Sun, 26 Jul 2020 18:15:12 -0400 From: Peilin Ye To: Laurent Pinchart Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , syzkaller-bugs@googlegroups.com, Hans Verkuil , Sakari Ailus , Arnd Bergmann , Vandana BN , Ezequiel Garcia , Niklas =?iso-8859-1?Q?S=F6derlund?= , linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Linux-kernel-mentees] [PATCH] media/v4l2-core: Fix kernel-infoleak in video_put_user() Message-ID: <20200726221512.GA102357@PWN> References: <20200726164439.48973-1-yepeilin.cs@gmail.com> <20200726173044.GA14755@pendragon.ideasonboard.com> <20200726180752.GA49356@PWN> <20200726220823.GI28704@pendragon.ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200726220823.GI28704@pendragon.ideasonboard.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 01:08:23AM +0300, Laurent Pinchart wrote: > Hi Peilin, > > On Sun, Jul 26, 2020 at 02:07:52PM -0400, Peilin Ye wrote: > > On Sun, Jul 26, 2020 at 08:30:44PM +0300, Laurent Pinchart wrote: > > > Hi Peilin, > > > > > > Thank you for the patch. > > > > > > On Sun, Jul 26, 2020 at 12:44:39PM -0400, Peilin Ye wrote: > > > > video_put_user() is copying uninitialized stack memory to userspace. Fix > > > > it by initializing `vb32` using memset(). > > > > > > What makes you think this will fix the issue ? When initializing a > > > structure at declaration time, the fields that are not explicitly > > > specified should be initialized to 0 by the compiler. See > > > https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.cbclx01/strin.htm: > > > > Hi Mr. Pinchart! > > > > First of all, syzbot tested this patch, and it says it's "OK": > > > > https://syzkaller.appspot.com/bug?extid=79d751604cb6f29fbf59 > > > > > If a structure variable is partially initialized, all the uninitialized > > > structure members are implicitly initialized to zero no matter what the > > > storage class of the structure variable is. See the following example: > > > > > > struct one { > > > int a; > > > int b; > > > int c; > > > }; > > > > > > void main() { > > > struct one z1; // Members in z1 do not have default initial values. > > > static struct one z2; // z2.a=0, z2.b=0, and z2.c=0. > > > struct one z3 = {1}; // z3.a=1, z3.b=0, and z3.c=0. > > > } > > > > Yes, I understand that. I can safely printk() all members of that struct > > without triggering a KMSAN warning, which means they have been properly > > initialized. > > > > However, if I do something like: > > > > char *p = (char *)&vb32; > > int i; > > > > for (i = 0; i < sizeof(struct vb32); i++, p++) > > printk("*(p + i): %d", *(p + i)); > > > > This tries to print out `vb32` as "raw memory" one byte at a time, and > > triggers a KMSAN warning somewhere in the middle (when `i` equals to 25 > > or 26). > > > > According to a previous discussion with Mr. Kroah-Hartman, as well as > > this LWN article: > > > > "Structure holes and information leaks" > > https://lwn.net/Articles/417989/ > > > > Initializing a struct by assigning (both partially or fully) leaves the > > "padding" part of it uninitialized, thus potentially leads to kernel > > information leak if the structure in question is going to be copied to > > userspace. > > > > memset() sets these "uninitialized paddings" to zero, therefore (I > > think) should solve the problem. > > You're absolutely right. I wasn't aware the compiler wouldn't initialize > holes in the structure. Thank you for educating me :-) > > For the patch, > > Reviewed-by: Laurent Pinchart :O No no sir, I'm just rephrasing that LWN article. Thank you for reviewing the patch! Peilin Ye