Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp65152imu; Wed, 19 Dec 2018 13:44:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wi5X2YXc5aFeaD48NTdW3KgBDrFB8Oljx26bw5ybY5RS3Y8mC4OkraM/4G7VJis8GoL0gi X-Received: by 2002:a17:902:724a:: with SMTP id c10mr22248196pll.51.1545255879412; Wed, 19 Dec 2018 13:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255879; cv=none; d=google.com; s=arc-20160816; b=Rg72cZjqTtv+hcp9HiXcA4zX1Q4YLVGbSUeeim/ei/pxIfurO33rNyGQIDugpDnjRE /Kw7YBJh/PwQ9y3VLa1GXPas2VitH6v9L1yJyEXMC2htqWhgs+4pJzsVnap4gkBbsUsy ERD4ZwfmX9osIo0ZOiMmmXtPn+ap02XAmMhVBItTmPUnz1U2TRSQSsHvfAkIsH+jByvp vSep5yKztONtAdYuj46fhOjgZgizxzDXE6tDpGoVzZRyQKkGMLz6UEibeeW+kc9jHgPS rS20jq+033Le8Fa+F522bfE8z+9o6M9tfAsYOGOKqKgoi1TavldAnXD8hbzXIQfqK+59 PGNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:subject:cc:to:from :date:content-transfer-encoding:mime-version:dkim-signature :dkim-signature; bh=b9wbPb6KEYvnbN1xm4lS4/BZ6alh3eksl98vIW+qKG0=; b=m/IPU2Plr9tJ4lELqrj/UINrfoFTywi5PBELItc4Np5EsnfMaFYL/nQ/9UvJ1TYy2J GSWkdprK3QcLEM8YCtf+xn2nHOWMAN1YlejxtXViQ7vidg8jIuoDh+kiG4oQO0R0xm2f 6374VpvSDjdb12CmwgWdwPao9eGqwlXC8LyCMPXTER4DviWqpcNdYD53xr0K225NL2Ao 8PAQMTBt1QIHCG22xSCpC4YhEv8LE7KnqC2EQ7vJ9iIJbXDH63AiBsLNZWA12h/6IuiY tQMakjJefYjEvm00Wth/a8QmuesfanCaAi0ueM7ULXfOvjvTJ+DlEyW2l8+hNsdBvM0Y 8clw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=mJSmQKnn; dkim=pass header.i=@codeaurora.org header.s=default header.b=dxjwamaQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c15si16604121pgg.446.2018.12.19.13.44.23; Wed, 19 Dec 2018 13:44:39 -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=@codeaurora.org header.s=default header.b=mJSmQKnn; dkim=pass header.i=@codeaurora.org header.s=default header.b=dxjwamaQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729276AbeLSTvV (ORCPT + 99 others); Wed, 19 Dec 2018 14:51:21 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:60100 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727602AbeLSTvV (ORCPT ); Wed, 19 Dec 2018 14:51:21 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 623C060591; Wed, 19 Dec 2018 19:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545249080; bh=VHZONW94vpYDHpBgGNvLYtF8q29VTjx+UYGnR6dinHw=; h=Date:From:To:Cc:Subject:From; b=mJSmQKnnX4ldHW1V7PMYV7YfRDtY6e/RtFGRQoIb8QXtE0iRkTGiKUArqswWeu1uM ntt58bmxbI4JfvM+s3W/kqkRmm/b5IaPDvo/7BAvyXSVQGmc49BnDsq0M+trFBVAXn cOOIt31y7xIB1cac0MetLbLZz6Y0mokDTJVYDlz8= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id C1D9760591; Wed, 19 Dec 2018 19:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1545249079; bh=VHZONW94vpYDHpBgGNvLYtF8q29VTjx+UYGnR6dinHw=; h=Date:From:To:Cc:Subject:From; b=dxjwamaQR1qgYBdpr5AoiMFh6GjwacpmZ0yd8H8+O9qqc8MIreTGoL9utxpSLXrK4 vuCM5mdfPnbUAsW9e5YDq1H7f5A0Mkdm6iOMlOZdqqMmXzI8pRK51+3QWzFktTMqb3 OeUa3yl+lkmvU8t63d/B7l2FOccM00ICnUMaNFjo= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 19 Dec 2018 11:51:19 -0800 From: rishabhb@codeaurora.org To: keescook@chromium.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Linux-arm Kernel Cc: tsoni@codeaurora.org, ckadabi@codeaurora.org Subject: usercopy_warn in __copy_to_user Message-ID: X-Sender: rishabhb@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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’s upstream work to change LLVM, so __builtin_constant_p works 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