Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp303600ybz; Tue, 21 Apr 2020 09:18:52 -0700 (PDT) X-Google-Smtp-Source: APiQypLQYnhJPnj2e1tWSQR+a+prxOBeCs0jEbI23+fmd1i3UpaQ3N8LJ6uiKqi3mA012HH2FqLV X-Received: by 2002:a05:6402:1684:: with SMTP id a4mr18617829edv.99.1587485932754; Tue, 21 Apr 2020 09:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587485932; cv=none; d=google.com; s=arc-20160816; b=XRuSa6TCu4h7k08c/XUZpSubUwm1J8aIYmNYW3F6X5CpoSrPOJs0hNSekMO1K61GkV C4Mngws7b78eIHzLPbKCtyqrJlBGg0Ad8TsYNAt1raqpxKYwvmPWK3OCPX5qMq78sAp9 JMSnlIEyOBwD+UHqaJvxEF5spS2R4n4WXgqzBimz08Fg7QDqewLFSXkwNp6PHerPS2TE IziUxeoL5kSuOJvRam3Y2u6rSu6y4pIdQfNY6FT09lPbFpUgHJ6dxzQqo1DXFUMoKMv5 N+CdH26dv97f7FVl9jTwl+wTx9ROPiyxjmBUISmJqmppVxoW8Sxj64RcrCq/aNKFRtdu lBuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sZb/G+BPZCnKqNsOXZmWC5vghAcQlH+ouaFUjXK/3AQ=; b=Df8YnTtNx6MuyPe9pHnug4iCoDhipLW7B5oRfZX+dfkwBPCG1opB6CB0EFR9VzZ6qC EoNiSNZSpzlOQX3MA3v1nr4LgH1e8/jjam+7CR6k04dRT3Fd0O/G2CsRYXFV4Bc8x7Rw Hkoz9gM/MqxQghC69UNwWYPg4BV7Ka0Tg1ip9vd72wLJdR1IiC1o8GtRDeXVvEmC2ZOX vasjz+c5RhWRA+cauCCwez53s/QgHbT1qwXGUtBXTR239fmxO5mPgdbdUf0etCsxYFJ1 XCv1gtyupBu8QL7doyDsOjIqkHH3lcBa2ko5XNX3gmdyRNZPN1Dq957jwC5iy4hztEMg uc8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NXEelkyD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si1992738ejx.28.2020.04.21.09.18.29; Tue, 21 Apr 2020 09:18:52 -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=@google.com header.s=20161025 header.b=NXEelkyD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729169AbgDUQQz (ORCPT + 99 others); Tue, 21 Apr 2020 12:16:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726245AbgDUQQy (ORCPT ); Tue, 21 Apr 2020 12:16:54 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2639BC061A10 for ; Tue, 21 Apr 2020 09:16:53 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id l19so12069512lje.10 for ; Tue, 21 Apr 2020 09:16:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sZb/G+BPZCnKqNsOXZmWC5vghAcQlH+ouaFUjXK/3AQ=; b=NXEelkyDEgdRL1G6FH5p2bLty3HGgMXhS0omaT+tore+VnjnCscaeRkZIkG0FdUEZ5 nKYoGvT1giT0+uB+hMl+Pm2c3/21ZLx+MS+mRYgvqVdokvuVAAV1LclnPMMl/PygRBMK 6MtBvJTPS+WVdN2pI09XNbg2guoLV2q3qgyybxloiX4Mmrw092X2L1nNZspfO7UJgTsp fcIlZX7uV5/7/2YznW0FpGYRbo+pwucTQaSvYrZEtTtrjqrUMdI22zhsSAGQtWkS5upo Zm4XjUPNb/JZ1ZWiFx+bUac7Hug/bhh3A48FbervaNkkjFnD+FzUygLkmnP+DMYYzUMO jr4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sZb/G+BPZCnKqNsOXZmWC5vghAcQlH+ouaFUjXK/3AQ=; b=dc/stbc73j/TtfQf8vhswexQA5I41tpEHw+FaE2WHAP0aBPlrAAdskxIgMdvWDqndC qyC0EHNht50jHmhTbKIHFcQEq5U1OuKdGXNE0gMK9UGQmd7vVjf7vG1B+mk7I2bNnK8w Vte9pHSbJD6iZ3hASKrjEE+aDNg9JCAJmg2jKMApsbEp0AeZoN5tVdBZmxQk+x+R6Lx9 WNP8IoYQM5sSqsCSZ8VIMJVXG6FeJYwBfH76podPRwwx+iPzyNXsifnHuFBca+S8o8ad ftNh6VcOomNDD80bHGA2ZVA1KGtsh30yeMHQIu57OsBOuxL0ka8SNC23sd4cxCLEcM+3 3+kQ== X-Gm-Message-State: AGi0PuZ3fdIItesWyG4aLlRsJNqMoZNtuLF0xp3fgGVNCHt6HLNKxaq0 5q0naYsVO2fpWoLorI7JMuEhGbbhywI5pgksfx1EnA== X-Received: by 2002:a2e:87d3:: with SMTP id v19mr4440555ljj.176.1587485811325; Tue, 21 Apr 2020 09:16:51 -0700 (PDT) MIME-Version: 1.0 References: <20200419100848.63472-1-glider@google.com> <20200420153352.6682533e794f591dae7aafbc@linux-foundation.org> <202004201540.01C8F82B@keescook> <20200421034249.GB23230@ZenIV.linux.org.uk> <6eb0a398097d16f7247accdfa9c21c1da90e0461.camel@intel.com> In-Reply-To: <6eb0a398097d16f7247accdfa9c21c1da90e0461.camel@intel.com> From: Jann Horn Date: Tue, 21 Apr 2020 18:16:25 +0200 Message-ID: Subject: Re: [PATCH] fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() To: Yu-cheng Yu Cc: Alexander Potapenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , Dave Hansen , Al Viro , Kees Cook , Andrew Morton , Alexey Dobriyan , LKML , sunhaoyl@outlook.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 21, 2020 at 6:05 PM Yu-cheng Yu wrote: > On Tue, 2020-04-21 at 17:09 +0200, Jann Horn wrote: > > +x86 folks > > > > (rest of thread is on lore > > ;, > > with original bug report on github > > ;) > > > > On Tue, Apr 21, 2020 at 2:54 PM Alexander Potapenko wrote: > > > On Tue, Apr 21, 2020 at 5:42 AM Al Viro wrote: > > > > On Mon, Apr 20, 2020 at 03:41:40PM -0700, Kees Cook wrote: > > > > > On Mon, Apr 20, 2020 at 03:33:52PM -0700, Andrew Morton wrote: > > > > > > On Sun, 19 Apr 2020 12:08:48 +0200 glider@google.com wrote: > > > > > > > > > > > > > KMSAN reported uninitialized data being written to disk when dumping > > > > > > > core. As a result, several kilobytes of kmalloc memory may be written to > > > > > > > the core file and then read by a non-privileged user. > > > > > > > > > > Ewww. That's been there for 12 years. Did something change in > > > > > regset_size() or regset->get()? Do you know what leaves the hole? > > > > > > > > Not lately and I would also like to hear the details; which regset it is? > > > > Should be reasonably easy to find - just memset() the damn thing to something > > > > recognizable, do whatever triggers that KMSAN report and look at that > > > > resulting coredump. > > > > > > > > > > Seems to be REGSET_XSTATE filled by xstateregs_get(). > > > Is there a ptrace interface also using that function? > > > > It looks to me like the problem KMSAN found is that > > copy_xstate_to_kernel() will not fill out memory for unused xstates? I > > think this may have been introduced by commit 91c3dba7dbc1 > > ("x86/fpu/xstate: Fix PTRACE frames for XSAVES", introduced in v4.8). > > > > There seem to be no other functions that reach that path other than > > coredumping; I think the correct fix would be to change > > copy_xstate_to_kernel() to always fully initialize the output buffer. > > Yes, that makes sense. On the other hand, the kzalloc() fix prevents potential > similar problems for other regsets. I don't really have anything against using kzalloc() there; but in my opinion that's not a fix, that's hardening. The real problem, in my opinion, is that regset->get() claims to have filled out a buffer without actually having done so; and if someone happens to add another caller to that thing in the future, I don't want them to run into exactly the same problem again.