Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp102484imu; Wed, 19 Dec 2018 14:29:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/XQAsa7m7bl24/cp0brFzfPBEkFmQUCfHtvjy44ZvdNhQV9etdFfokUWCXkUBjwvWfs0jyN X-Received: by 2002:a62:5658:: with SMTP id k85mr21912175pfb.231.1545258571225; Wed, 19 Dec 2018 14:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545258571; cv=none; d=google.com; s=arc-20160816; b=agTgKnCHLedwrZsG3guJR0tOX57Cmfx9FvZH4l9AQttA3XNW2hAEB79BapzD5sGgfh sqskjNkZd28qQLmWBcVJ+ESiurG+x1O34wRJ0CB8OUh1UgsiZPKRZlxt5BPTqxah0jZ2 mRhq/5BLHnW2tzwn+FYI0OnD8iLBnV4f/V8XwZF9KRRJxhzp2DP8qYjZP9iBcHLY9S1a cYxoDVIefufvd20dWS7KAK3unRnBKhaHU/sp6Ph7WEjJKSFgBCYQg9IE5L5y17SdIqNg Lmwm4vXnMOzrDjK8VPxunHDsY9KjNElhVQEetWk84YtkHJ5+aCF7pPNgqpFfy6S7A17e sChA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GM5hGu4M0G7cLJiG/Agci333y79vb/B6Mg/bPozxqbQ=; b=Wccfqxbky9IkubpewcwQFQHmla8IagQB0G7NnHx9BmpyHAuLFFKw/IEYebejLNVF3F ZDOBDXHh6ytHXLdRflolopPA1volEQgWSL04NGkkvEBg7S4QeSXVCFACyGgrzlTUot2F fieQZVdBlZCUPbB0AxZmToe91WXXd1BCKAamisloJVnQG/S1BHEULIibB1f6i7a+r6p5 WJhyc69LcLNtoHUfvj9BuUNbTobxhyVBqnE+QIHUtHF0gmirzlkBHBausgVm/uYS5Jqs w7mi3FK2pzpEEXef/OcaC3WQJ2xwQRm2iECjN4BA5nriH3F16ZADBzz426fSNIIFTmQq I7cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d0UhBioK; 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 13si16807429pld.398.2018.12.19.14.29.15; Wed, 19 Dec 2018 14:29:31 -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=@chromium.org header.s=google header.b=d0UhBioK; 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 S1729414AbeLSVve (ORCPT + 99 others); Wed, 19 Dec 2018 16:51:34 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:45667 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729183AbeLSVve (ORCPT ); Wed, 19 Dec 2018 16:51:34 -0500 Received: by mail-yw1-f67.google.com with SMTP id d190so8752966ywd.12 for ; Wed, 19 Dec 2018 13:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=GM5hGu4M0G7cLJiG/Agci333y79vb/B6Mg/bPozxqbQ=; b=d0UhBioKbOj3lUW4AGfleaR68HWYnVZ51nyMcG4O+WkRY3xIcpbjHL3t8lSkZPAkRg cWh00QeeQeSnJZQ5dJk30aggq6GezcAXHtyUyz6B0UFLiG/a1VChq4/l+jcxjcnvOrzk dj4vJSRiE4slCuvIBEKYqRGIZdIkmkPwvRxqg= 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:content-transfer-encoding; bh=GM5hGu4M0G7cLJiG/Agci333y79vb/B6Mg/bPozxqbQ=; b=joJ0hRTt5iCIYibMee0yD+S8gKVqaOFgm7YL8lsJGYCVJN4MnXFwrvjNHOmoObAiGh VRSTZJGpHLJbUR8yq+Yreq2ZgKVoQWbEmYagI59Ck8UOaC69Jhw1LeNo48qsVvjzb30y JB1PDoWlXbpHmPUjxQzXTtSxl432UXMHpjGqOGS/n05ZrxNhwyO/m+Yhk/TdCXRhvZ3F +mIr1gvRaY+R2aDrxnoyTKdrv0ct5w2HzR6phbCdubzYN47246G0y132YGWPqijf2Jf2 4yhKXiCUAZGQkHZBNNTwdvMcA+rbNfYpPQuecQ+Y9z+aE3/5VS2Zcd72p4JjuH8PSeUM ObDg== X-Gm-Message-State: AA+aEWaIMJHoLbZG4Wv0rZuij++FhXcbczOClmCRGp+3jgTc9JD14jDl 02qXB3XcIFfk/wO+a2hWEE7zqJpqYmw= X-Received: by 2002:a81:7342:: with SMTP id o63mr22825597ywc.131.1545256291971; Wed, 19 Dec 2018 13:51:31 -0800 (PST) Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com. [209.85.219.172]) by smtp.gmail.com with ESMTPSA id i21sm11616082ywg.5.2018.12.19.13.51.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:51:29 -0800 (PST) Received: by mail-yb1-f172.google.com with SMTP id 64so8502271ybe.3 for ; Wed, 19 Dec 2018 13:51:29 -0800 (PST) X-Received: by 2002:a25:a445:: with SMTP id f63-v6mr21956262ybi.171.1545256289326; Wed, 19 Dec 2018 13:51:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Kees Cook Date: Wed, 19 Dec 2018 13:51:18 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: usercopy_warn in __copy_to_user To: rishabhb@codeaurora.org Cc: LKML , linux-arm-msm@vger.kernel.org, Linux-arm Kernel , tsoni@codeaurora.org, ckadabi@codeaurora.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 19, 2018 at 11:51 AM wrote: > > > In the 4.19 kernel, we are seeing a USERCOPY_WARN in __copy_to_user > during bootup. > The code-flow is something like this: > > (arch/arm64/kernel/signal.c) > struct sigset_t *set; > __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)) > > (include/linux/uaccess.h) > __copy_to_user(void __user *to, const void *from, unsigned long n) > { > might_fault(); > kasan_check_read(from, n); > check_object_size(from, n, true); > return raw_copy_to_user(to, from, n); > } > > (include/linux/thread_info.h) > static __always_inline void check_object_size(const void *ptr, > unsigned long n, bool to_user) > { > if (!__builtin_constant_p(n)) > __check_object_size(ptr, n, to_user); > } > > Since sizeof(*set) is constant, __builtin_constant_p(n) should return > true. > But we are seeing that its returning the value as false. Because of > which > the code goes on to __check_object_size and generates a USERCOPY_WARN > ("usercopy: WARN() on slab cache usercopy > region violations"). > > We are using LLVM clang version 6.0 to compile the kernel and not gcc. This is fixed in the latest LLVM and Clang: https://github.com/ClangBuiltLinux/linux/issues/7 -Kees > In clang, __builtin_constant_p is evaluated immediately, before inlining > or other optimizations run, gcc evaluates it later. > We believe that maybe causing __builtin_constant_p(n) to return false. > There=E2=80=99s upstream work to change LLVM, so __builtin_constant_p wor= ks more > like gcc when optimization is enabled, but its still in progress. > > > For this scenario is there a way to avoid the warning? Should the code > be > written in a different to avoid dependency on compiler? > > Thanks, > Rishabh --=20 Kees Cook