Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3978185ybg; Mon, 28 Oct 2019 23:49:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBLLHURwOGEeoaUs3zfSK2FwjMAI6FFSnr6ckzo+1LRqAxXt7ll90eYg+Tj74x0PCvIc2d X-Received: by 2002:a50:d713:: with SMTP id t19mr23921731edi.185.1572331793353; Mon, 28 Oct 2019 23:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572331793; cv=none; d=google.com; s=arc-20160816; b=foN3+++Sc7v4Xj+AMfVhCPpUdlXwhU9lTt5lTUzZbNLYmq50dete684RBP/jVs612H ibrQ1uob6y/13zsDyGg11GVxV9h2+Ox85wmT3aJSuTZdpPS/tc6y9Kfo41vqSBTsKn4p 1xWmhaWDa3jV24NNIL3UFL2Q4seNf2HKGF6+JnkPXsZYZlQ/rgms77IUAEboY+HBm/bh svm1YZEvW8EYYvN0+Nakb4dGovRm2EEOqlKpWK5V367mFDuGFe7WELiP1qb3/OYGZv9C P01O1ZIIVs6GSc5bVb98ExDMOd9K0kg+BHPVR6Y9r+2z/Eg4iA/G7ZX4hApcWQZEA7NB kACA== 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=fUjCn4Cs3vWoZSNWz7xz1odhXxITVOufrvXvl689LIk=; b=VEudxbxKZdQV+U3UkuV551DAtn28Z/1GrwCxrAxlnudxiVo34HvcF438fCE4z0t9oL ls60i6eGUJ5FB3xlq6ARqocqsq+9KH7Tmq2ClC91tsPTeyM9BIHgW9cXk6zg3T3DuFBY eirXqlCuIpbMwyvteSqJlxIODY9UpPLkqmb9qanSL8GNZELjbvhfuO/6o1XqsYGxcjRU Cm0FqHj/0xwEkwc+vX2fiP5HJZ7325ZmajLb/T3PqJ0cALdmYxodSPxN3+tixJhCFnI7 P2CIUII7NXkaTwPchXH6di4uWEMAq8oGt6Lav8FAVSVIHeW5FxkF1VCpi5PJWifMcis5 T7CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TjSZDWhp; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si7566949ejr.229.2019.10.28.23.49.29; Mon, 28 Oct 2019 23:49:53 -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=@chromium.org header.s=google header.b=TjSZDWhp; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729224AbfJ1S6h (ORCPT + 99 others); Mon, 28 Oct 2019 14:58:37 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35367 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728969AbfJ1S6g (ORCPT ); Mon, 28 Oct 2019 14:58:36 -0400 Received: by mail-pg1-f193.google.com with SMTP id c8so7527732pgb.2 for ; Mon, 28 Oct 2019 11:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fUjCn4Cs3vWoZSNWz7xz1odhXxITVOufrvXvl689LIk=; b=TjSZDWhpawWLvh7U9yF8Z3jUBz830zCPqkTwFPuCzqYXztKH80ZIskPCrsn1pHaNKG AhI81kWQyaSPVqrGKZ1kwltiruez+QL5qTqXqBzO5QDgV0kKtx+rqhatn2X++XH8UXVQ 9Ik+Xwa6jMrh08hhFLROmv2BHy9Zov3o3Ke5Y= 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=fUjCn4Cs3vWoZSNWz7xz1odhXxITVOufrvXvl689LIk=; b=pCKT15jgqM2Ftg+zIimyaVGNAU3BNgpRGTQIuzLb9m+cnnSegJw6v7aTzVXE6dNNZf YfP53yx3cuP/y/ynj5SOd2Jx8JUTc6x/uN5Yr/CH/3jB99oyhtGw6i/6GZXVVt7KFPNT gIFHieMtO67+3XaNEmQI/Y4PHPf647j9iN9OmtzBj6mQh2N81jMFnCflPfvFyk/LSCMm G/fVijNPwgScA3QGan6odypqTChb8vSvrBvfV0ZKYVX0LU6vzwL1uWEzxHBpf/yLbgao iixns0/9mbePo4BqTWl+4nh01rkE5CBEzVt6KHT68m8CYkwtwSq9LatqABk8Z9i0Ho05 bapg== X-Gm-Message-State: APjAAAVeP1ETup/b5k1O92JOLLq0AgEp6RL8N7CkHCMR5sbLzYD8mL+F hcKVaUwVp5Px/xGk//FShPYvsA== X-Received: by 2002:a17:90a:d58f:: with SMTP id v15mr1010425pju.17.1572289116194; Mon, 28 Oct 2019 11:58:36 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d14sm13531892pfh.36.2019.10.28.11.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 11:58:35 -0700 (PDT) Date: Mon, 28 Oct 2019 11:58:34 -0700 From: Kees Cook To: Joe Perches Cc: Julia Lawall , Andrew Morton , LKML , Dan Carpenter , Thomas Gleixner , zhanglin Subject: Re: [PATCH] kernel: sys.c: Avoid copying possible padding bytes in copy_to_user Message-ID: <201910281153.7B6F79DBD@keescook> References: <92212e57d45f4410be654183f5dcb1e98d636ef2.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <92212e57d45f4410be654183f5dcb1e98d636ef2.camel@perches.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 27, 2019 at 03:47:21PM -0700, Joe Perches wrote: > I think yes as at least it makes it consistent. > > From the link above, as I understand the __user > gcc extension here > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c61f13eaa1ee17728c41370100d2d45c254ce76f > > gcc does not clear padding from initialized structs > marked with __user. It seems to depend on how complete the initialization is and/or how large the structure is. AFAICT, based on the tests I wrote[1], if CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF (or ..._ALL) are used, even padding will get initialized as long as things are in memory. (And the same is true with Clang under CONFIG_INIT_STACK_ALL.) > Though that doesn't force the compiler to not > perform the possible register optimization shown > in the first document above. Right. This is the only case where things aren't clear. I haven't been able to build a test where "store in registers" behavior is tripped. -Kees [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/test_stackinit.c -- Kees Cook