From patchwork Sun Dec 9 20:44:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 10720375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AA6E112E for ; Sun, 9 Dec 2018 20:45:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E66E2A0FD for ; Sun, 9 Dec 2018 20:45:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1224D2A109; Sun, 9 Dec 2018 20:45:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 4476C2A0FD for ; Sun, 9 Dec 2018 20:45:24 +0000 (UTC) Received: (qmail 11444 invoked by uid 550); 9 Dec 2018 20:45:22 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 11411 invoked from network); 9 Dec 2018 20:45:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QNaI3hDAMnUXZFjlHQHpvHuAp7kuC48ucAbx4V8btwc=; b=NC7tOk5WhKeOvqzr3cxn9lEQ1e8117UHymSLTKFys18259B7ObIPwrJjJqau2LcZPs Mko4AqGTobSiIuXMh0AxUcgvtEU8IeQpOtM6XIMhgIMerHag722VJ6imuPPI/rZwfUYp a0ngz5Wp62M2JsonOUaR6cgXNGQ/kiJokuXUTibthbVeK4rJo7BVHPlFFhmWfZItyL/W 0OrN/00Q9gKuoDlXPnYq24Z9BLGX6mJ5UHcCRl8WEN03b3R21dFp00ZO0Xs9q8jlhODw jp2Urr9oHSeB1XmzmSR97Xk4ap88+ZV0EfPdXYQwV1AaR+rTAUj5YGV+c5TcoV3qCJgk qHCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QNaI3hDAMnUXZFjlHQHpvHuAp7kuC48ucAbx4V8btwc=; b=nlnKH5Ey3y+C75pOhERZ4nbpGHR5gGy7ZHFsy3MdPT0J4VQtWkLud5DHomqAR0+EmB TQ3cbjZu1yekUr0eIbYMVSPQ/Dtq0+xm8V6/Rp3guSfu3z2hcVA9IUsJWGfIew7NWwKa jP5caQLdHK8fMeD2nD6SOV4brv6P52Ywu9DhlHLW+Oa7yKvB3CyD481TpZ/AHEYt1GhF pzJAg6EX4QuVhl37HwqAMtEtZZGv3I3vuK86WBNwPPfsz9eXcdOOtqx5hUfGqlwjcnHm 3pZwrf8mye4F5s8MFRmHTHhLRHSlRIaWWzkMPhOYFtWOLZQYPRc6uVxPu0KS3oqO7Rm2 U8FQ== X-Gm-Message-State: AA+aEWZEShiBCZLsHN8eRH3NmpexUf9DSmy6IAc4MaGmFgDcZDWxeo35 ScThJQmD+vQCehr4qgN9VekIfg== X-Google-Smtp-Source: AFSGD/Wpe5dEucVsQv8KJvYs/vlhm3HYWH9HLw0CHQ3mYEO7+yTgbjo+qSBHfN1wX0UBrWcMX7M2TQ== X-Received: by 2002:a02:95e4:: with SMTP id b91mr8532356jai.15.1544388309320; Sun, 09 Dec 2018 12:45:09 -0800 (PST) From: Tycho Andersen To: linux-sparse@vger.kernel.org, kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, Tycho Andersen Subject: [RFC v1] copy_{to,from}_user(): only inline when !__CHECKER__ Date: Sun, 9 Dec 2018 13:44:49 -0700 Message-Id: <20181209204449.18906-1-tycho@tycho.ws> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP While working on some additional copy_to_user() checks for sparse, I noticed that sparse's current copy_to_user() checks are not triggered. This is because copy_to_user() is declared as __always_inline, and sparse specifically looks for a call instruction to copy_to_user() when it tries to apply the checks. A quick fix is to explicitly not inline when __CHECKER__ is defined, so that sparse will be able to analyze all the copy_{to,from}_user calls. There may be some refactoring in sparse that we can do to fix this, although it's not immediately obvious to me how, hence the RFC-ness of this patch. Signed-off-by: Tycho Andersen --- include/linux/uaccess.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index efe79c1cdd47..f20a2d173e1f 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -140,7 +140,13 @@ extern unsigned long _copy_to_user(void __user *, const void *, unsigned long); #endif -static __always_inline unsigned long __must_check +#ifdef __CHECKER__ +#define uaccess_inline __attribute__((__noinline__)) +#else +#define uaccess_inline __always_inline +#endif + +static uaccess_inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n) { if (likely(check_copy_size(to, n, false))) @@ -148,7 +154,7 @@ copy_from_user(void *to, const void __user *from, unsigned long n) return n; } -static __always_inline unsigned long __must_check +static uaccess_inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n) { if (likely(check_copy_size(from, n, true)))