Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2270842ybf; Mon, 2 Mar 2020 05:28:01 -0800 (PST) X-Google-Smtp-Source: ADFU+vss3ZxCkditsYXFVRVA0JXjP4hL4DuIHuHQd9+OIDYh+11b0UT6ed+5sKLW9QV2CYthbJeU X-Received: by 2002:a9d:7d04:: with SMTP id v4mr3486240otn.308.1583155681312; Mon, 02 Mar 2020 05:28:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583155681; cv=none; d=google.com; s=arc-20160816; b=bAf2I0HDcKZ1Aeq18UaMz9Rd8/6e+848sU6hSllJY+g0xcPUSgx8nH6J39G1QqQkIn eboGd9EA/2swDDR0ytP/AhbByap5mLyM+uiksx4KoFPaglKx0NSxjUMltqmaafxXVBvJ ucOJNysQU8T8m42e/iFh6nuD4yjN9AZRILt2DFhjE659n2RIpmogH7QOHm87+3xbw80j VRdkRfPDkSqqwbdq2xNhjIcIAjG5SoA3BQtYscy/tpzLiNRHAy5XBbm1raVFdORRf6F8 GR9/KFoQyXl53bMTjstTU0pVDoJPaBuEm+MigS1/dnvu4b8/o8EnWjDL3GIljq3+3Tfb qLwA== 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=2ksuLQhQaVfn70PglWjMPhyebhvTDpJOHYR+Eolo3CI=; b=o3Q6mEMIPYXLlrqX5Xa+FQNEkslHRL574WJcoF/79BvkapOlWkpKpoB/Smh4BUXg47 EoKl1XRE4v6ejiULLjSHVKk2jzZVoDL4tvwkAMOsTq6l3Iq+fuXqP/Cr+q8dO5NJxt+2 dpSNHZm1UwX4+tzRDckUEell6+C61qyU8ecswL9wA+wXkkKPIBgnkgzOXVkIZcxEed+d sGG6gDFowEO5hLE58unTsvmMGW9/PIFTYhty5fAQ6JFVemkabjLIXPzRTpnrTXmzPnic qSxWGY1fjsqcg+jyn31lDizUxpe9/uh05rm/RTrJAlyrFfPwBaOlubyciEMvij3D4XkZ On5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="kg/Ix5ng"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c19si6617921otp.129.2020.03.02.05.27.43; Mon, 02 Mar 2020 05:28:01 -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=@google.com header.s=20161025 header.b="kg/Ix5ng"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727769AbgCBN0G (ORCPT + 99 others); Mon, 2 Mar 2020 08:26:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37893 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727627AbgCBN0G (ORCPT ); Mon, 2 Mar 2020 08:26:06 -0500 Received: by mail-wr1-f68.google.com with SMTP id t11so6168468wrw.5 for ; Mon, 02 Mar 2020 05:26:03 -0800 (PST) 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=2ksuLQhQaVfn70PglWjMPhyebhvTDpJOHYR+Eolo3CI=; b=kg/Ix5ng9Mz+UXqDYAMU89aLZdgeaLpX4W30gQT8rcTasW1GpdIE8NKWxAtUZyRzTG ALq6z0sTmxSMYl6IPPgzZPA8iar3y6hmHb/eZ0uffkyfINUKungQFokafBTWdikN5RBR dI35lgDn6AnQsX1VziRKtNj/mzkywL7xshBxa62FvMo2cbFZ8Dc1skpvOnG6RE3XitM2 xI/BXIomb0qKYEWrQQ69B6m7ehaiVzDwt6QHXwfXdtyRn0luJY5dXeDlsSDtFBYDP2yF dyCd8vO5HwgOYRwEzyqINWoi9hKBGFcpC4mjibqy+WM2gqk8DvJaXdsojuzVUBX3vtRJ hTdw== 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=2ksuLQhQaVfn70PglWjMPhyebhvTDpJOHYR+Eolo3CI=; b=f3JfHUkgUsJaKP9jfEMBa4zPndEDwwqC7pxr1sRw0fjx8MKQYjKyE5BhriYY0rYqDB F9PsvRD4FFz1y+iMWY+2FzSX4XH80H/SGIVIPHL6/baBa9NlRV1K/pvDbUaFMqpeQ/yA G8kRPDKASwQhsmQpGBRpL0KdbG8WTe9yYDKUcdBQCwk0J7Qiw7rbpRPXjgeTXghvLWQN K+L5qUt3qLiBjzOxHpvvHhPQGEfLVMc/L0uPde7yy+7N3VFtsjhHXZTTL4rGd6xqpGWT 6HiA7ikPepY8OB+Sy1DppaDA6UHNrFlK2b2XKRA6PtbUyB3FnTdsMoOBsspNfinIu7Ci z0Tg== X-Gm-Message-State: APjAAAVCMBinrpB+r2Q/404ecLcrQwK+AwvZbYRp1n2Z6sy8lpyORHdv NxxnOhdxFRTuNlZ8J1PNpSgssYF8K749cnJOQ9eEug== X-Received: by 2002:adf:ef4f:: with SMTP id c15mr22486054wrp.200.1583155562342; Mon, 02 Mar 2020 05:26:02 -0800 (PST) MIME-Version: 1.0 References: <20200302130430.201037-1-glider@google.com> <20200302130430.201037-2-glider@google.com> <0eaac427354844a4fcfb0d9843cf3024c6af21df.camel@perches.com> In-Reply-To: <0eaac427354844a4fcfb0d9843cf3024c6af21df.camel@perches.com> From: Alexander Potapenko Date: Mon, 2 Mar 2020 14:25:51 +0100 Message-ID: Subject: Re: [PATCH v2 2/3] binder: do not initialize locals passed to copy_from_user() To: Joe Perches Cc: Todd Kjos , Kees Cook , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Ingo Molnar , Dmitriy Vyukov , Jann Horn , "open list:ANDROID DRIVERS" , Peter Zijlstra , LKML 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 Mon, Mar 2, 2020 at 2:11 PM Joe Perches wrote: > > On Mon, 2020-03-02 at 14:04 +0100, glider@google.com wrote: > > Certain copy_from_user() invocations in binder.c are known to > > unconditionally initialize locals before their first use, like e.g. in > > the following case: > [] > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > [] > > @@ -3788,7 +3788,7 @@ static int binder_thread_write(struct binder_proc *proc, > > > > case BC_TRANSACTION_SG: > > case BC_REPLY_SG: { > > - struct binder_transaction_data_sg tr; > > + struct binder_transaction_data_sg tr __no_initialize; > > > > if (copy_from_user(&tr, ptr, sizeof(tr))) > > I fail to see any value in marking tr with __no_initialize > when it's immediately written to by copy_from_user. This is being done exactly because it's immediately written to by copy_to_user() Clang is currently unable to figure out that copy_to_user() initializes memory. So building the kernel with CONFIG_INIT_STACK_ALL=y basically leads to the following code: struct binder_transaction_data_sg tr; memset(&tr, 0xAA, sizeof(tr)); if (copy_from_user(&tr, ptr, sizeof(tr))) {...} This unnecessarily slows the code down, so we add __no_initialize to prevent the compiler from emitting the redundant initialization.