From patchwork Wed Dec 19 21:33:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738159 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 149611399 for ; Wed, 19 Dec 2018 21:34:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05357286B2 for ; Wed, 19 Dec 2018 21:34:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED71F286B4; Wed, 19 Dec 2018 21:34:11 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D646286B2 for ; Wed, 19 Dec 2018 21:34:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D3228E0019; Wed, 19 Dec 2018 16:34:09 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 256988E0001; Wed, 19 Dec 2018 16:34:09 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 122018E0019; Wed, 19 Dec 2018 16:34:09 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by kanga.kvack.org (Postfix) with ESMTP id 9BFE48E0001 for ; Wed, 19 Dec 2018 16:34:08 -0500 (EST) Received: by mail-lj1-f197.google.com with SMTP id t22-v6so5935902lji.14 for ; Wed, 19 Dec 2018 13:34:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=zzEjOKOluUUWksw+oXnin6HXgBufUkueAJaYjC1prj4=; b=MGirugYsYM+kxQFed/PEAN6z5LAnKnY3bc+DRktYEje9J4HFIWIyEi88meomXynMW6 x6E30+9zzX6KbOMCasRTzpGi0Bc/BxL9BX34uRq588xTEwzSAna1aQOdve1OdIAYntQb HE2Qw7hqfNAztVji1dheUKfLie/gPOQDUBLGxszFrsvgB04xfAbxIukN78WVVv+eu3Gs K5W6SBQZNWNGKFDU4UYDc7nCdWuT9N7moMNkCsXyG5z/HaVMXy6SnGusKUd/IRd8fw9o qqPhT5LXzazdGjekFUXNWbcoIp0QghpKfTO7yZawCcFgSY7tqybZKpMOW2eczXMju1/w cGxw== X-Gm-Message-State: AA+aEWboadfYL9gbaf+NhoCbjZwGiWR/dKpnAztu/u00cuqeHdLaPNhg 93PxH6kjg8L3fss6bXsgOkIkH6/aatEAqkHc/iLZJ8Wq4YNk4gYNy1+UD1i52nk6GsFos9r8AJa p2o2mVUha5rgf6pLA7Bo1ffTAZxLapYb2zj+0kQvzQoxsFHWnB54ABflR/WE/vJY7KhkRJC0XOH lq0r1llqnS/g+KWg/YbiAdyABvGnJOXq5aI3dOJ8nWzZST8fn0w+Gu61dOHhMEgVi+fnLxHiqPA rMrcRy21NHWtuSsVBwhMDWsZ2FDPf/zBv3Kl3H+N2uCFiu2VNdCpUiVcyLunQuAQSGutqUjWd+H r53Oj5vYBrRk9Bb0Ay4nfF4PNFPmikVi70O0Ph7mkKQ8FVx9H8s+Jse0t/+kSstz0SB/MGvNJra E X-Received: by 2002:ac2:4215:: with SMTP id y21mr13364714lfh.6.1545255248033; Wed, 19 Dec 2018 13:34:08 -0800 (PST) X-Received: by 2002:ac2:4215:: with SMTP id y21mr13364689lfh.6.1545255247005; Wed, 19 Dec 2018 13:34:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255246; cv=none; d=google.com; s=arc-20160816; b=l6yGS/NKrkImc7YdCvmi45BqfTMoiAyjuWS1+vYC/cX0ZedDDiSVHbYl9vjNvUi3ah HPoPQevSiRt93bWY71pWxLeyIQieGFgNvd3xlqfYGXNKzxZi84a234dsGYvMGENgE2LD 4X6wph1ljS3JTHmbwCfTtvYvQm/IvFgDb54AxDsv9yD+SGajDWnoGceU2SiKMjed3REB HQgdfj1GhMDX7XC/FP+jlKIEXqpNWB+dxVB3wr7hYWCzkiVujMMXKPUZo1m265JnGiKa S50/+WmkLdUMk3ZF1kUqKFzO/SJJwt/XfaTvThtQIN5J8Zz+1gC5tklXWiYUTZatMzBN Awvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=zzEjOKOluUUWksw+oXnin6HXgBufUkueAJaYjC1prj4=; b=RiSDFcPOwBf1ExW83IYRremU/cIUEI794f2TMw0quyEE3ExmE3lUq52vsGfIP2+2vT PZNu6k21ExcqVXHJ49g8Y1x2D1FezmVftZ8xSDtdrJCbRAGlwANCr6Kivqs4X2SF3bVM JMjI8zXaBSjQgMx2/nsG5qrPu5k+bPztydstdJmt0iIGTEEiv33/dlmd+WTOTc5qePOl M7knisjHl18yFsyCuPHC1fdk6OUbqHYHQ2qZo4VuHuOkH58WIPxc0oDacZQLuHJIUDAb dkOGxCJ/szmluvpbsbjSeSbi4X/P3g59ddRtKqlpVmA3EvdZ8v+NyttogfNBAAZMEHCv FpDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CWCHozxt; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u10sor5741072lfu.33.2018.12.19.13.34.06 for (Google Transport Security); Wed, 19 Dec 2018 13:34:06 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CWCHozxt; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=zzEjOKOluUUWksw+oXnin6HXgBufUkueAJaYjC1prj4=; b=CWCHozxtXPaF/R34zIBV9kgAuN1gg0PddkrPC5aWleCfLISFSDUnCKYlt1SLfa1Qdf AbBcVlgs7IbX/SocNOSs7TJQFHB47Mb19vHQatLapdRgx2CO4a1kc145mUHuA0wziXHH QzZ8yM8QB4lZEUShcVat6wzXvLInx64kvRel1qGAK2FWOTDIZ18UCt14KqSiQ4ShML9x rAO14BDpxcuPoIQYRNZAzrNtOpMAw7VGp3iOilzQ4tI6o+kS0TZkiyLu0KCkKArZ5UO2 dPjUBiO0nyOIiEfyvkENuq9RLsdpeA4AjYW6bWLilccCTnnGGCpqqA/Quth/AjuruGh3 tVQg== X-Google-Smtp-Source: AFSGD/WxAkE6ImfOjvKiqC6CvFghm5iWxm8HjnpQw4GJB94Y1GY0BzHPXMXipEe8534UoMRhUUvpBw== X-Received: by 2002:a19:6514:: with SMTP id z20mr6123044lfb.31.1545255246483; Wed, 19 Dec 2018 13:34:06 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:05 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] x86_64: memset_user() Date: Wed, 19 Dec 2018 23:33:27 +0200 Message-Id: <20181219213338.26619-2-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Create x86_64 specific version of memset for user space, based on clear_user(). This will be used for implementing wr_memset() in the __wr_after_init scenario, where write-rare variables have an alternate mapping for writing. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/include/asm/uaccess_64.h | 6 ++++ arch/x86/lib/usercopy_64.c | 54 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index a9d637bc301d..f194bfce4866 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -213,4 +213,10 @@ copy_user_handle_tail(char *to, char *from, unsigned len); unsigned long mcsafe_handle_tail(char *to, char *from, unsigned len); +unsigned long __must_check +memset_user(void __user *mem, int c, unsigned long len); + +unsigned long __must_check +__memset_user(void __user *mem, int c, unsigned long len); + #endif /* _ASM_X86_UACCESS_64_H */ diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index 1bd837cdc4b1..84f8f8a20b30 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -9,6 +9,60 @@ #include #include +/* + * Memset Userspace + */ + +unsigned long __memset_user(void __user *addr, int c, unsigned long size) +{ + long __d0; + unsigned long pattern = 0; + int i; + + for (i = 0; i < 8; i++) + pattern = (pattern << 8) | (0xFF & c); + might_fault(); + /* no memory constraint: gcc doesn't know about this memory */ + stac(); + asm volatile( + " movq %[val], %%rdx\n" + " testq %[size8],%[size8]\n" + " jz 4f\n" + "0: mov %%rdx,(%[dst])\n" + " addq $8,%[dst]\n" + " decl %%ecx ; jnz 0b\n" + "4: movq %[size1],%%rcx\n" + " testl %%ecx,%%ecx\n" + " jz 2f\n" + "1: movb %%dl,(%[dst])\n" + " incq %[dst]\n" + " decl %%ecx ; jnz 1b\n" + "2:\n" + ".section .fixup,\"ax\"\n" + "3: lea 0(%[size1],%[size8],8),%[size8]\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE_UA(0b, 3b) + _ASM_EXTABLE_UA(1b, 2b) + : [size8] "=&c"(size), [dst] "=&D" (__d0) + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr), + [val] "ri"(pattern) + : "rdx"); + + clac(); + return size; +} +EXPORT_SYMBOL(__memset_user); + +unsigned long memset_user(void __user *to, int c, unsigned long n) +{ + if (access_ok(VERIFY_WRITE, to, n)) + return __memset_user(to, c, n); + return n; +} +EXPORT_SYMBOL(memset_user); + + /* * Zero Userspace */ From patchwork Wed Dec 19 21:33:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738161 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 6C0E51399 for ; Wed, 19 Dec 2018 21:34:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C0A8286B2 for ; Wed, 19 Dec 2018 21:34:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FAC4286CB; Wed, 19 Dec 2018 21:34:15 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A14AA286B4 for ; Wed, 19 Dec 2018 21:34:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 060AA8E001A; Wed, 19 Dec 2018 16:34:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F00108E0001; Wed, 19 Dec 2018 16:34:10 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D38848E001A; Wed, 19 Dec 2018 16:34:10 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id 5BCB68E0001 for ; Wed, 19 Dec 2018 16:34:10 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id x18-v6so5938169lji.0 for ; Wed, 19 Dec 2018 13:34:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=scWZE0nWnwTd+0FVwhDij4gwRZDyVIgA4bUgU9jm4Qw=; b=HzL2Ct8B47YAxHL8p522HqRCiIIvXNdt4DKNOq9dgMEyhONUCjDmAosJ8G+R3D/225 rS5aABuLXmC1XnFuQA3CUxKw+pePdXRAlmzinS9DBj9/nh7BfSMT+Q+xU+v8jiNj+y6Z lwXvCcP9GbikXbD541mzQq/rEU1KvJG0IegdfSLeyCu6Hzgi1gb7E4L+o93BJYEqxV6p CTncYqn5fCCUZ9vO+1BAHqeZcIlUUe3rPGoEHwYVNwxi+FvmozkQQpITVIR+bOeiWgCI UQkUczL5mxQCEs+ktOEXJS8z/ybC3D43ayYYh8Y6UnIU/Ixmo2cQ63h8Ed2L3YhpIlw4 ESzA== X-Gm-Message-State: AA+aEWY8rbOoXMpD7J6/brzoOOn+bj+ji0RcqRRPxJ/7YatUSOOl2dXO KbdR5hyvECtD6C/13A2+LRk4JeCaJaS9Y4Z65miTRJwLQ+yrnbnIOKRLtAd1SVlkf+DUeew9YCA o1330Wy0o2Vhk1eq8NNEUeXyOSDkIQGcdjYBh+SwUZ2z+aOm6pifKqxLLzhEJTJfbqhZdsGkWgd hHl7YJN4G/X9dSdBDgE5hLe9/TeQYLJYM/wTUxUPKiZ4OuMnSgKqRmjBbf5HSk4Ze4UQHrHiS6c sbv3TuF3CBPJDyFv5/zJwLwEOL5i89SwhPbEwqTqcDLBD5VkDXFn1D1d6nA8V0WC+/ZM/iLIicn /QZHXN4Xmc4Mgs+N46vOp4UY2GkyRTtHkkzRmuHJCnXdkG5OyC5MpcBrzmMoCHKl2rTOg76cui6 7 X-Received: by 2002:a19:ae03:: with SMTP id f3mr14232647lfc.86.1545255249704; Wed, 19 Dec 2018 13:34:09 -0800 (PST) X-Received: by 2002:a19:ae03:: with SMTP id f3mr14232619lfc.86.1545255248608; Wed, 19 Dec 2018 13:34:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255248; cv=none; d=google.com; s=arc-20160816; b=agTaDejprHT4xGnKYJhFtZN96sZFTeSc73+gPoASRSfQiTW1jFPMvjh9eX5LCWqTjg hqkiO2fR94rap10x+d36TQil0pzF/Be4Nu5LVby0hV2Okbgh8EgCFd6jpf4CgOiE9Eip pZPTVYtflIiqFj+H8MzjgnrEWV1tgohBg6p1slaYo9fEdTHcCkRHM/hI1Jlz0rIBR6X1 +qZVtqjhhMXeLw6i30rCi0ffooyH2iaFhYl+5XY9k0SMFFb4jgiNAyW02qyBAtD6Iana KrvUF2GGfdxRoywQQPw2jYKnBpcsdFCHUEd/GJh+YCQMFMcRPed0NOzwiGUe+SzMNZC0 ieXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=scWZE0nWnwTd+0FVwhDij4gwRZDyVIgA4bUgU9jm4Qw=; b=dqIVmGH5uhUwn58iMAWPY8Vw9kAvmnaPLqoMexmNSfsQhd0gnYgOhk5e/KDkNiB+Tn KH18ulN9g0ddHa6UscEozln5UZQ2PQ5zxDYHLpjR2EnLyDBUcfnfes0W05NTJ1gzzRoM ava2oTN78Tfn+8+PIvyJTBk28qCv67PzfFHbAmXohWzHI+VGamTlaBR0HLnWmtygu91V ruyTDpk7ssDCxq6WXedI0MsEpTPdskeuYEDXOznwBxgfbk2UctH1X4lOFU/1CDd3YL0l IhtvdUvPdU6AtZ+yqsJ5n6Z2oJmZ3PQVwtwHisQLgdQFGz9YUIu9Pr5uhZsZiVnVZKqP 31TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ECXYO49y; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b23sor5649412lfa.6.2018.12.19.13.34.08 for (Google Transport Security); Wed, 19 Dec 2018 13:34:08 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ECXYO49y; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=scWZE0nWnwTd+0FVwhDij4gwRZDyVIgA4bUgU9jm4Qw=; b=ECXYO49yQdsxme7Jgttlgkk1OXF/pQaB16kIMgz5hObs81P2rf53rdtsbq9vuqLTnT jX7gpNLiv7n2ncpWcBw+TV1SPHoghJKVMmyBOzVunlBAW61kLMpZr1w3iqUXJQoeIKEd brnyV5ix2RB7j3HEu34jkYRtexvm/NhrNxTfEAvkekM6qgJOc/YlTSrGbQY/Vl1JRFjx vUOH/DytpLM810A0HmxqVAf2g4zZX/YJL1WbFzWl0Mg2GTodhUeSoi+UJUiQ/AAA4RPC Jbrz4ug0xFFizcuiOeNzDKdpaBPg6nJAXr8izbvHwNWU2BmKHoXdLtFkNMw7Vc0D9izd VsJA== X-Google-Smtp-Source: AFSGD/UUnkuvBJtrj64z76vEVRzpp/gNTMhY363jcuYcBn4wBrr23AJH+tdTR+9OboCCOslwcSXVpw== X-Received: by 2002:a19:2906:: with SMTP id p6mr5307891lfp.17.1545255248175; Wed, 19 Dec 2018 13:34:08 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:07 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/12] __wr_after_init: linker section and label Date: Wed, 19 Dec 2018 23:33:28 +0200 Message-Id: <20181219213338.26619-3-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Introduce a section and a label for statically allocated write rare data. The label is named "__wr_after_init". As the name implies, after the init phase is completed, this section will be modifiable only by invoking write rare functions. The section must take up a set of full pages. To activate both section and label, the arch must set CONFIG_ARCH_HAS_PRMEM Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/Kconfig | 15 +++++++++++++++ include/asm-generic/vmlinux.lds.h | 25 +++++++++++++++++++++++++ include/linux/cache.h | 21 +++++++++++++++++++++ init/main.c | 2 ++ 4 files changed, 63 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index e1e540ffa979..8668ffec8098 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -802,6 +802,21 @@ config VMAP_STACK the stack to map directly to the KASAN shadow map using a formula that is incorrect if the stack is in vmalloc space. +config ARCH_HAS_PRMEM + def_bool n + help + architecture specific symbol stating that the architecture provides + a back-end function for the write rare operation. + +config PRMEM + bool "Write protect critical data that doesn't need high write speed." + depends on ARCH_HAS_PRMEM + default y + help + If the architecture supports it, statically allocated data which + has been selected for hardening becomes (mostly) read-only. + The selection happens by labelling the data "__wr_after_init". + config ARCH_OPTIONAL_KERNEL_RWX def_bool n diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 3d7a6a9c2370..ddb1fd608490 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -311,6 +311,30 @@ KEEP(*(__jump_table)) \ __stop___jump_table = .; +/* + * Allow architectures to handle wr_after_init data on their + * own by defining an empty WR_AFTER_INIT_DATA. + * However, it's important that pages containing WR_RARE data do not + * hold anything else, to avoid both accidentally unprotecting something + * that is supposed to stay read-only all the time and also to protect + * something else that is supposed to be writeable all the time. + */ +#ifndef WR_AFTER_INIT_DATA +#ifdef CONFIG_PRMEM +#define WR_AFTER_INIT_DATA(align) \ + . = ALIGN(PAGE_SIZE); \ + __start_wr_after_init = .; \ + . = ALIGN(align); \ + *(.data..wr_after_init) \ + . = ALIGN(PAGE_SIZE); \ + __end_wr_after_init = .; \ + . = ALIGN(align); +#else +#define WR_AFTER_INIT_DATA(align) \ + . = ALIGN(align); +#endif +#endif + /* * Allow architectures to handle ro_after_init data on their * own by defining an empty RO_AFTER_INIT_DATA. @@ -332,6 +356,7 @@ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ RO_AFTER_INIT_DATA /* Read only after init */ \ + WR_AFTER_INIT_DATA(align) /* wr after init */ \ KEEP(*(__vermagic)) /* Kernel version magic */ \ . = ALIGN(8); \ __start___tracepoints_ptrs = .; \ diff --git a/include/linux/cache.h b/include/linux/cache.h index 750621e41d1c..09bd0b9284b6 100644 --- a/include/linux/cache.h +++ b/include/linux/cache.h @@ -31,6 +31,27 @@ #define __ro_after_init __attribute__((__section__(".data..ro_after_init"))) #endif +/* + * __wr_after_init is used to mark objects that cannot be modified + * directly after init (i.e. after mark_rodata_ro() has been called). + * These objects become effectively read-only, from the perspective of + * performing a direct write, like a variable assignment. + * However, they can be altered through a dedicated function. + * It is intended for those objects which are occasionally modified after + * init, however they are modified so seldomly, that the extra cost from + * the indirect modification is either negligible or worth paying, for the + * sake of the protection gained. + */ +#ifndef __wr_after_init +#ifdef CONFIG_PRMEM +#define __wr_after_init \ + __attribute__((__section__(".data..wr_after_init"))) +#else +#define __wr_after_init +#endif +#endif + + #ifndef ____cacheline_aligned #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES))) #endif diff --git a/init/main.c b/init/main.c index a461150adfb1..a36f2e54f937 100644 --- a/init/main.c +++ b/init/main.c @@ -498,6 +498,7 @@ void __init __weak thread_stack_cache_init(void) void __init __weak mem_encrypt_init(void) { } void __init __weak poking_init(void) { } +void __init __weak wr_poking_init(void) { } bool initcall_debug; core_param(initcall_debug, initcall_debug, bool, 0644); @@ -734,6 +735,7 @@ asmlinkage __visible void __init start_kernel(void) delayacct_init(); poking_init(); + wr_poking_init(); check_bugs(); acpi_subsystem_init(); From patchwork Wed Dec 19 21:33:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738163 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 0568414E5 for ; Wed, 19 Dec 2018 21:34:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A3F286B2 for ; Wed, 19 Dec 2018 21:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDCAA286CB; Wed, 19 Dec 2018 21:34:18 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EE29286B2 for ; Wed, 19 Dec 2018 21:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 343328E001B; Wed, 19 Dec 2018 16:34:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F3588E0001; Wed, 19 Dec 2018 16:34:16 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1961E8E001B; Wed, 19 Dec 2018 16:34:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id 9B21B8E0001 for ; Wed, 19 Dec 2018 16:34:15 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id g12-v6so5964139lji.3 for ; Wed, 19 Dec 2018 13:34:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=K1qd1aZR2KQTVV+zbS5hJl8R/gTgxGLt3TGWSatHUyxq2v2oZO/Dy2NMgrdN5AKYIX AhfSNwHzU4MLisa6Ye/fYD06LlPmWGd1QnNQFmPWgCioph9HBHET33UNgRBe/0bCHbnC 8LqoXkUgnGk7dhoLCwoL+31K6vOZ5XZtgmgTsmnK6UcmzDKkcdGW7mPxr0wmixz17eT6 v+jBY0zxEipfGqdjAsH/ZSxk1TI3pApJmqT5l+yBdd2m09r73VATRrSta9WAAJKRJnej VCAeB1xIaAp+84bToSV6tBgecjxUAZhlg2CBmNUCUF+QUijar0AhTDUxRSDchcEiYqI1 5r6g== X-Gm-Message-State: AA+aEWZXceup6oFRHHRrAmwVYEW4Vxa9vk7fOjt7EjeUywH8I5xPHVR2 Y+IiugAJ2vWqfa4juRSTcOjESIPWfJQbHGhJ0mxLsOLwON5V/TitkeYhdE6elyXlQheE7y3Qd5T qDvmzA/KBxrOe+QQ4G43EoxFgStReLf5YQOEasyWVmSlc5mC3FRXKTSdiebJKmBbFlb3UFZt5is u8L9sWCehh9ljh7FxjvKgOnl5Kre8opGg6eEnIso6P+SrDuPNlfCTZSjhm+5o02Y13qwqZKfCN6 Qifh57/LGrXKMd3f/MWMfqiSyYkjkirMh5DZ8iJC9Poc2hntLNMylnlcASu7478jDgTzTPiAoRg 7y4HZek690d5/6ihQzQAKkc7BSRxyD9GGnopkCgwMBl+ZM51fWy2OVV8DJiJts1SqoV7OKjJ9Hp U X-Received: by 2002:a2e:9655:: with SMTP id z21-v6mr3102736ljh.136.1545255255050; Wed, 19 Dec 2018 13:34:15 -0800 (PST) X-Received: by 2002:a2e:9655:: with SMTP id z21-v6mr3102709ljh.136.1545255253998; Wed, 19 Dec 2018 13:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255253; cv=none; d=google.com; s=arc-20160816; b=GfRbzP/v/a1DvXsEFenmaHEzC5biwS4F/5YaKFT79Jcew4Hvz5dLHNfUBOxsj76YpC smnF2arXDDAfTTRP/GmYmzPU9WkK1u4regOiebPF/nPFsFHWL0QxI7qk0AZJEu+OnKEN Nxwu8QJzTkqfMpanUYuLITQorrvgFHioNaY6ejc3Sac1qMPZTLRrs8SVzBovTG0UmWGt COcyff5cUwCYkphg0O9NjEOS84EI7jo4wiWQgSon3OOtWVf+E62k9iDxUqDtEdLcc9YR EttAdPv78KKEPNbg2d9RMQ2ZBSojx6jIABdpHojIawAHm4d2SsaiXnrrXrZ7C9eYyS6r Qb1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=Wd0o6RxIsItUgMEGw3MvR0RRSVE+eNxsfUsR2LeiKfIqfJfO1Re0eD4jShHGm/f2uS j7/UaDr05E3Fh6Kl6kzN5oTb5eWCVXMLlsFsU0ItIzxE9Ec5L2taIIPPb9SKtSjSHAU/ pKaarK9ePRN8O1yeTehwg28ntWOFxAoKk2VHvdosqYz0zQDuNP7LpyDwfHVr3nPqFMnb A8CnyMJChTzz2UzY5uS2bf2k5FnJH8zpH6qcO95h6zXlnYpKFWwz7WHT3aZQe29FJjQ1 ZaAE4p0pFiVspUSPszxgBNgAPWFyLXgX7bDw/6N61W2jyvMwRKGT9G0+pTckcL9pGHUY sM/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PsrHxLPq; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f18sor5726516lfa.66.2018.12.19.13.34.13 for (Google Transport Security); Wed, 19 Dec 2018 13:34:13 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PsrHxLPq; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=PsrHxLPqAAOHeNu5dAOofHFnXp1bLF9bdTdCkJocLpMY34bZfpnS8iWf5Dw2UELMym Gs5mW3HgNBDw5r9JwJTc0Fq3/dkKkbXJS7j9ubeXSvaALWLkByds7T+R2raJoj5RB0Us PON54gmyVQYYU1Mhmt0vzo7LMuv0p5iO1KZA6Qk3Upr5Y64fRgaifZvHyDj0R8B9QWJl BH+63gFqXdkbK13Syi/DwqnOPOJoBavpGBrbHbeAijtUwGiWjznREdZkOCpw0ARGA5FE 7YraB7oodasyYu4ih5gVedVO/3YOfqhU5mGxwIyA1M6Q8keXB3YNZROEWIyRN9g1/NkH hOCg== X-Google-Smtp-Source: AFSGD/XZWonxcWlW1GBfKWAbMcZ0oFNcTXt0omhVGDk3miIbt6GEElW3TXO8yTUpmBSwSEymuJbaRw== X-Received: by 2002:a19:910d:: with SMTP id t13mr12712428lfd.98.1545255253625; Wed, 19 Dec 2018 13:34:13 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:12 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/12] __wr_after_init: x86_64: debug writes Date: Wed, 19 Dec 2018 23:33:31 +0200 Message-Id: <20181219213338.26619-6-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP After each write operation, confirm that it was successful, otherwise generate a warning. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/mm/prmem.c | 9 ++++++++- mm/Kconfig.debug | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/prmem.c b/arch/x86/mm/prmem.c index fc367551e736..9d98525c687a 100644 --- a/arch/x86/mm/prmem.c +++ b/arch/x86/mm/prmem.c @@ -60,7 +60,14 @@ void *__wr_op(unsigned long dst, unsigned long src, __kernel_size_t len, copy_to_user((void __user *)wr_poking_addr, (void *)src, len); else if (op == WR_MEMSET) memset_user((void __user *)wr_poking_addr, (u8)src, len); - +#ifdef CONFIG_DEBUG_PRMEM + if (op == WR_MEMCPY) + VM_WARN_ONCE(memcmp((void *)dst, (void *)src, len), + "Failed wr_memcpy()"); + else if (op == WR_MEMSET) + VM_WARN_ONCE(memtst((void *)dst, (u8)src, len), + "Failed wr_memset()"); +#endif unuse_temporary_mm(prev); local_irq_enable(); return (void *)dst; diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 9a7b8b049d04..b10305cfac3c 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -94,3 +94,11 @@ config DEBUG_RODATA_TEST depends on STRICT_KERNEL_RWX ---help--- This option enables a testcase for the setting rodata read-only. + +config DEBUG_PRMEM + bool "Verify each write rare operation." + depends on PRMEM + default n + help + After any write rare operation, compares the data written with the + value provided by the caller. From patchwork Wed Dec 19 21:33:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738167 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 98CC76C5 for ; Wed, 19 Dec 2018 21:34:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 864FF286B2 for ; Wed, 19 Dec 2018 21:34:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A6E9286B4; Wed, 19 Dec 2018 21:34:23 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66CD7286B2 for ; Wed, 19 Dec 2018 21:34:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4562A8E001C; Wed, 19 Dec 2018 16:34:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 404DC8E0001; Wed, 19 Dec 2018 16:34:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A6ED8E001C; Wed, 19 Dec 2018 16:34:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id AC6278E0001 for ; Wed, 19 Dec 2018 16:34:17 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id g12-v6so5964165lji.3 for ; Wed, 19 Dec 2018 13:34:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=xeUBKKu9pM2Fl/EWnsAPb2mBNLFsikzJ4KNY/hC/k1s=; b=quWJBUhGqChDTvBUzcE0IcVG7oWeoLi3o3SDFJ6DxCr77qGQ43KyRiBD+HaBCjAcYN V7bArZ87HfaklYBxtLxCZmO3xxGUgf3maDEGXaZQqktlg7HMNjDM7YTqyIw8dVFJE6bI H23Dv7vtbUxl4rfg383Rvk/dD/HbXgCRGG1vDWLgs4ux3XEtGf0Pqq5ygKa0pYwr9Iru gPDV3oOEmFQJHljaywubT7LR6JvKjB4WisY0GtL2mYunzfXQKDNJ2IT7AgvtyJ2pZXoU XYR2XhBrg6bR9PiaciucP+MDNNY4W3bKHukckrGLWtdLzlRoDYPfV/IQcZQ5iB0/hmZ7 u4zw== X-Gm-Message-State: AA+aEWbnLVSdlHa6jL7t4vJBGy695s8Xxw9zwyhIihMwjlWnTgpdXZGh vb80QMQL4oW7Mb08jW2zVNv4abGQS1ya40rE/PIUUoVfpoMiPGXdmBrsaEkEamQxde7S1hGl2n0 YFSENszKTKRjor6yAepYzUi38Ec52lpTlb/TOy2XYXAtjnv7gbtbWxJhOZeS331A2uFmVAWUQla /7LuyeYmiNk4oqT0Y6XVrOOV7LwIdnVXaJEkBUXO6CcqRgBb7qmQn5tYEh2a2FdptgaTZk0EuwY 5x9Y4A1cgDWdzf2hT9lOx3xML7AwKisUyYRSPFNMRQXMLmlqEgj/xRFKK4qH+aNq6fjpr34fzop OkWC5FlCkSOv8+PCwzSdjAoEefRo8aN0NH3LtIzue1mNGY/rl6g9Aqr+Dt3+l3vHKId3J69E2Xq h X-Received: by 2002:a2e:8945:: with SMTP id b5-v6mr7345208ljk.55.1545255257072; Wed, 19 Dec 2018 13:34:17 -0800 (PST) X-Received: by 2002:a2e:8945:: with SMTP id b5-v6mr7345176ljk.55.1545255255756; Wed, 19 Dec 2018 13:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255255; cv=none; d=google.com; s=arc-20160816; b=bdA0hEjzCRK5z7KWNPJD/PF0vCUj8lYtHVcw1AvLgqo0WFrf8EEuY6KanxS/WK71Hx ucFX9Zl+xMLXfjZrwXAnz/veyj9H/te2IiI5SkjwhUkFThHY3/u5HaoDvLG9C8JgwOMw DOiIzYvHTIk7rCrVNLa/5tVCBdqcBE9J6MifRDvvUGKBbWNz6dQ23WEKAWfgoqFHH1in +acGcOxYIsdVnJfY3JpSvekCuUq1zaaXlOlryFlCATlx68UDTFEPDypnW/aJjGPelUDj IXaYzxqwpTtESHfd2PWQS6ssJyqTpBA2RLeCMI4dqZdAb1+KxamNtK0WKFpou6eXToaq IAgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=xeUBKKu9pM2Fl/EWnsAPb2mBNLFsikzJ4KNY/hC/k1s=; b=ccZcjF43wjcHOrVy8AiHyTm2gM75Th31gRoWQgulvXZubqolCIBHh/57ztD3p2nVOP LAiyF1iKze4l7Dmj7LqJPXPNoZ368OM8oBdAY24vQ6L72NKosj55Gscjypat/HHlwZlV mzh3qs50/sUTIwejMtYtsk1Kd8LMUWdRo8GitU4lofnwHniny0sqLF6tBpMlQNZlXWH5 Esv/Sws1I+/qoHgTyuyYLsn+45IfTuHGDp0iSEgcU16mZxeYg4klZeBv8dUDC1T9zouU 5zHN43GGuhnpBNyDQTgnlkBO6K3CJ/ua2sdMuSg47iv1cWhcVXmjt9zl016qxI0Xgyfv E6vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TZIKF4B0; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h10-v6sor12552733ljf.39.2018.12.19.13.34.15 for (Google Transport Security); Wed, 19 Dec 2018 13:34:15 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TZIKF4B0; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=xeUBKKu9pM2Fl/EWnsAPb2mBNLFsikzJ4KNY/hC/k1s=; b=TZIKF4B0i3koI0BW8axIrrGf4qCRSgVc8vuBMQJuNZ1qpAqlmGEW+bOBxwCcDK/JY3 mNOXn/Lytz0LlgdZK6s3JlI7atnuH7qez7sfQofkmzbIV2f2ZxskOsfp9NEhU5NaQTvN tFggyM8mgzKvz7s8hU9qqgBsaUM8BAmUcWFYR5zWO8a3RW+FvppFPc9fZecShjwJLJh/ lBOqekityzb82UV0NrQDkyhgmPQox8nu6C1HKMReNtzcl/z9UGLkONLrC6fFakRwXStK q/7/hXtBDqCHpIXqfHQ2ugAPMEwgUpSvY+la3Uaoflk84Jo7xJduNGkOWP+FAq0r1yMl V6EQ== X-Google-Smtp-Source: AFSGD/VdVCH5iML0R9nPvIbiMPCBw0CGtT0CPJuGwuUVLfPeSRuvFLi8jSpphGe6vqzW2o8lG9K3Jw== X-Received: by 2002:a2e:890b:: with SMTP id d11-v6mr4048231lji.113.1545255255391; Wed, 19 Dec 2018 13:34:15 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:14 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] __wr_after_init: Documentation: self-protection Date: Wed, 19 Dec 2018 23:33:32 +0200 Message-Id: <20181219213338.26619-7-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Update the self-protection documentation, to mention also the use of the __wr_after_init attribute. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- Documentation/security/self-protection.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Documentation/security/self-protection.rst b/Documentation/security/self-protection.rst index f584fb74b4ff..df2614bc25b9 100644 --- a/Documentation/security/self-protection.rst +++ b/Documentation/security/self-protection.rst @@ -84,12 +84,14 @@ For variables that are initialized once at ``__init`` time, these can be marked with the (new and under development) ``__ro_after_init`` attribute. -What remains are variables that are updated rarely (e.g. GDT). These -will need another infrastructure (similar to the temporary exceptions -made to kernel code mentioned above) that allow them to spend the rest -of their lifetime read-only. (For example, when being updated, only the -CPU thread performing the update would be given uninterruptible write -access to the memory.) +Others, which are statically allocated, but still need to be updated +rarely, can be marked with the ``__wr_after_init`` attribute. + +The update mechanism must avoid exposing the data to rogue alterations +during the update. For example, only the CPU thread performing the update +would be given uninterruptible write access to the memory. + +Currently there is no protection available for data allocated dynamically. Segregation of kernel memory from userspace memory ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From patchwork Wed Dec 19 21:33:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738171 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 67BB2161F for ; Wed, 19 Dec 2018 21:34:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59196286B2 for ; Wed, 19 Dec 2018 21:34:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CF0C286CB; Wed, 19 Dec 2018 21:34:28 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89FA2286B4 for ; Wed, 19 Dec 2018 21:34:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 516F28E0001; Wed, 19 Dec 2018 16:34:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4CB8F8E001D; Wed, 19 Dec 2018 16:34:22 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FC3B8E0001; Wed, 19 Dec 2018 16:34:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id ACC158E0001 for ; Wed, 19 Dec 2018 16:34:21 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id 18-v6so5805876ljn.8 for ; Wed, 19 Dec 2018 13:34:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=bKSIarv0w1KwaUu0qi7xx9vxIAPD27FkzBk7lz41z35sv+/sW4qWm/1dDUfdl7nB4a o5D/EllB4/mzvpClIKWapGQnK/rL47ZGRP8LXllv/4NR2R+z+d/5ToXmzYspTsQ+DF5Q o/vx3ruiXESdjxFIxc95eTUTe0vYqlAC01OkUu/jRfhFDFPwZyi3NN+JMPwz3GeTewad /chQV/wlW7R33aceA44lNodWeb7l3WXwGA7JG0lXbqqdYroWbvXm+vDLd0mAtSP+Yyg1 /bkra0Gkwzaka0b9clk9KRdcPCOErpX0QXPm+RV06r3MKFOA7rOAAZOrGhFiQ/TuHspJ vp1Q== X-Gm-Message-State: AA+aEWbBtqd9Dnp9lgEdrs6DHxtdh6G4IUcQckIGfslYlCKPQAOmXBca mM1i08buxt1ymMsW7kje93Kq0VuiufcAnD0dKZBz5SIeqU/jesRTucaKC/G2Er0fDS+4RMFIeCh TLHBTdYLqXWZabE4um15O0dcO8lAhbX0Zf8SLoMoEBfHM4QCmyQywWLcDdvUjkEEVSXw7/n14vm ooBlEPa7t/cF0RhV2SpPCBkKLVCslJ7YJbOe6hPHl7qLW4OgGelCMSQlPLvK7I8vcBT8q7YuK3D Ec7qkukQ6mGM0og5c5mOkxG55xZA0o3co2X1NfOmb9ywSUjPDoaoopdPTx1J+MyJbL8YfJTIdaB Hq8ZytHAMeahHfWLg5TyTwU0uW0itkvR1dFoS4HY3cYdCfJ01uvZ3XytjZXmQf0KTT23ZMwAW6c u X-Received: by 2002:a2e:58b:: with SMTP id 133-v6mr13011681ljf.127.1545255261109; Wed, 19 Dec 2018 13:34:21 -0800 (PST) X-Received: by 2002:a2e:58b:: with SMTP id 133-v6mr13011651ljf.127.1545255259823; Wed, 19 Dec 2018 13:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255259; cv=none; d=google.com; s=arc-20160816; b=S+4t6PtfbFIIqsMpDG03x/n7jYywNhfNANzy761Xq4/7cBbBuq9xMYqxioLQHuCfV5 1ZECpCI0T0H52mgHcxiTaIAwF9iRK+wBAxvExjz4ctjUYNwZED83bQyxtDLI8LoMrk72 Ya4x9OGO9FvY4+dk7S9fXYvR8PtYcoKrIlU0L6M/HDW1pVXBnthmxwbeeQ1TN3doHJ/K tBiSE/Nv2FfkI3O0ZqB7w+SmJXrvdEV5dGbvNMG7vJjGhE00xKo5mNO+3r050t+WkXs7 cMtKQh2i/yPLxQSxuEEwdifTx7erl8nkz2rjZCzRH1DW9hHSa3xEJIwdBwWEFcRn4ltf 1Uvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=QmPT1RvB3Wqc9XJ2gM3Rv2MQZjQkEgP6VIXW+W3Zb3OTr5JSALwO+222jfVYTAS8R0 fjrwP/7VS1NygBpqJxcdycmuHyXd/N7wfqUnoXRWPXaNcKZqmWcwtfzCoeI3ZEMHEG3A uRv+9ptoS4y+/SORewYcfCQ/+lbyW9xOg74XbDQ22jUf+/tdzDHCM2mCT4SwwyfAdsne Iz8Ng8144pCdRvZYT+DqGnGTcaSfWenr+/kf5NrfwJKNUai/o/TmTX+Jl8sDWC+7iuRM /1kNHgqzUW0gZfPkaqjGRW0lOClmiDxccG7O7iRRZ0CiyMsu3fgxrHJgv816NJdHLE6v zEag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="poGcWw/a"; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j188sor5623375lfj.72.2018.12.19.13.34.19 for (Google Transport Security); Wed, 19 Dec 2018 13:34:19 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="poGcWw/a"; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=poGcWw/a5dJN1e4IsKUTg9pMbxoGjkckyx8MaSkIr8aVIRng3tIcIrdZ7bIpwBd1aW /Dj6i5fqZOC7b6xeP5q+VcNLiipYZbnUbSanuScQx6ZaQW9f5b2Xc5P/F/qzTZVierGT Rd6CLxydzbm7Mo5/8Hgsx4sm9C32VGSlCBeCSB9A/b18FgE2P5go+U/9Ibz9AFsHQ4YE avQ097RseD5F7PI14K0mNcIC26Xs55WgqRCaGNpums6/2CHHlkW/alMX3lufYGhYovJp I/Fnbo+3KnK1CiTtnCbj4tjLXBQ9xQMrqk97gx2+rBN1d9247ZwYsu/LSWuWqhwEXB+p azjw== X-Google-Smtp-Source: AFSGD/XS2Kzx9OR3BTlvyctmNLbS6bmvi/yoWDfNmmdJC+n2aSmi3aLbOa8u5dUsvtPjgDv0jk8AaA== X-Received: by 2002:a19:5402:: with SMTP id i2mr13050911lfb.128.1545255259391; Wed, 19 Dec 2018 13:34:19 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:18 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] rodata_test: refactor tests Date: Wed, 19 Dec 2018 23:33:34 +0200 Message-Id: <20181219213338.26619-9-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Refactor the test cases, in preparation for using them also for testing __wr_after_init memory, when available. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- mm/rodata_test.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index d908c8769b48..e1349520b436 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -14,44 +14,52 @@ #include #include -static const int rodata_test_data = 0xC3; +#define INIT_TEST_VAL 0xC3 -void rodata_test(void) +static const int rodata_test_data = INIT_TEST_VAL; + +static bool test_data(char *data_type, const int *data, + unsigned long start, unsigned long end) { - unsigned long start, end; int zero = 0; /* test 1: read the value */ /* If this test fails, some previous testrun has clobbered the state */ - if (!rodata_test_data) { - pr_err("test 1 fails (start data)\n"); - return; + if (*data != INIT_TEST_VAL) { + pr_err("%s: test 1 fails (init data value)\n", data_type); + return false; } /* test 2: write to the variable; this should fault */ - if (!probe_kernel_write((void *)&rodata_test_data, - (void *)&zero, sizeof(zero))) { - pr_err("test data was not read only\n"); - return; + if (!probe_kernel_write((void *)data, (void *)&zero, sizeof(zero))) { + pr_err("%s: test data was not read only\n", data_type); + return false; } /* test 3: check the value hasn't changed */ - if (rodata_test_data == zero) { - pr_err("test data was changed\n"); - return; + if (*data != INIT_TEST_VAL) { + pr_err("%s: test data was changed\n", data_type); + return false; } /* test 4: check if the rodata section is PAGE_SIZE aligned */ - start = (unsigned long)__start_rodata; - end = (unsigned long)__end_rodata; if (start & (PAGE_SIZE - 1)) { - pr_err("start of .rodata is not page size aligned\n"); - return; + pr_err("%s: start of data is not page size aligned\n", + data_type); + return false; } if (end & (PAGE_SIZE - 1)) { - pr_err("end of .rodata is not page size aligned\n"); - return; + pr_err("%s: end of data is not page size aligned\n", + data_type); + return false; } + pr_info("%s tests were successful", data_type); + return true; +} - pr_info("all tests were successful\n"); +void rodata_test(void) +{ + test_data("rodata", &rodata_test_data, + (unsigned long)&__start_rodata, + (unsigned long)&__end_rodata); } From patchwork Wed Dec 19 21:33:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738173 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 622A56C5 for ; Wed, 19 Dec 2018 21:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5185C286B2 for ; Wed, 19 Dec 2018 21:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45F76286B4; Wed, 19 Dec 2018 21:34:34 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA498286B2 for ; Wed, 19 Dec 2018 21:34:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C1EE8E001E; Wed, 19 Dec 2018 16:34:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 873638E001D; Wed, 19 Dec 2018 16:34:23 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EBCC8E001E; Wed, 19 Dec 2018 16:34:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id F12378E001D for ; Wed, 19 Dec 2018 16:34:22 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id j24-v6so5927773lji.20 for ; Wed, 19 Dec 2018 13:34:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=wZ8trlwQPC9hiGZKEv5EaYDHKPPRSKQ7DlpYkIOznGo=; b=LJrTIm3Gkg3wwz6OvuQbJFDImRXzSWKHoRlk8VLdef0uqx1Mw9B/IR4Y/6MuZf755A RyLMH88nG56HEGmEbQ/Ab0sRjmaWlQ+zORZo+acmXT/avOD6ERFG/fnBsRjTkR0/2JLo 8F9gHQzVm0ARwTbVpsD02pD5zFFFeUB4+IZVX8rkBD+9I35KKLep8+2Biwk4lHelHTwC tR5HK3OZBbZVhL9kEhCYvQFbFIY8vqUGoCww55l7SKmpxJb1Yw/+BrYmNqvwUf6HGE3n 12f10g4bAoz0U2lL5+qVPeXAv3jkFfLDQdDFCvsfGVEE5/o1fqX0oUOKdA95aFix/doU zJxw== X-Gm-Message-State: AA+aEWbHVbloqn7XYa/mIiKNg4ueYLP/hSNSYaX+OOgEd1pr529PUO8K vVCJD/5LI0dsImGSPMs80NyqLRxAAVjVO7kvfNOXOajA7FTjrU33zzSAGcZI6ce1M3zPqxOM/N5 5F9Dbn7QSDv+0TynlWeNOlnap7CdwcfljnZFEk0V6hLFoj60Jwn00PtNvhw40fJVf0Kkj1P0w9L wQYSmkJVqFf7Mnru2Nukoz8+PAmHDkZmlPgWivqAADwP8vMdtEvX0Dmv+tei9RARKxlZ42ybI4g pyJ5zbojtabUvt5KQ7k/ykIM2Ui5OYPlSbwl7zJRKBCbrE/eJvz3yCm1BdTblFjAa06EL8zt0Tq 1f2/5l9I/TlIVcwQd+fyQ9xxnA5V2oduwCqJzAmHanD/pqLiF0pXi7bk7cjG3c56HsFh5DWavst E X-Received: by 2002:a19:c650:: with SMTP id w77mr14053398lff.56.1545255262418; Wed, 19 Dec 2018 13:34:22 -0800 (PST) X-Received: by 2002:a19:c650:: with SMTP id w77mr14053368lff.56.1545255261533; Wed, 19 Dec 2018 13:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255261; cv=none; d=google.com; s=arc-20160816; b=xqUdtyW7NAT770LBB02OJsdmtD+Kq0YiNj/u/q+8omPYyc7msczT8JUJXeQX6Yic77 d2YQhjZA9vDQGBwJNk0bZqKaQSYcNB1sFj1QNcUWB/RIJirEOl6AdrzN7i+UJg6UF1Oo +e78Qu8ltfKgcBhqhh+c/dJBHsPzZkv5y1reYcSCWdIPDWHFCeyv0rJy7SzNooLCKs76 RKc4vBSvwCJsI9ffOZiWAOb/yCVyb8HvYLE2ItM/h7pCdmIm6ljYLWPX748xHAu/vegX LUfkg4REZja6z1nd3YLmghhHPvBcgA+tef4KYM8SAiNdCB2tVEfEUBFMhFveox4cQRgd nsCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=wZ8trlwQPC9hiGZKEv5EaYDHKPPRSKQ7DlpYkIOznGo=; b=GXXD9a6MVXjOIbRbytcGNk7Xf96YuEZjBODUtK0nMKCWT6zKLZh+4tRcGBirZH71Ww bCGAEFs4K9qEg1t+iA6gz4yRZVe44hghPTadMt8y2PzVAkNHMdFVX1fLHoGvPWsT7KmN 0kHGZC/EF1QZI01z6EMBHef7TSCQ0cjCTsL5LMsnVucN7Y50H19+qwTy48olczIyij2O C+CaYFn1w5UziTW3lJ3sdlNrq53hNhL+gkRhQ9VtT3IJZLAyBOy4vV8JBHYOsnbMjVC1 WQg9IdaBNZAgsRdZ+Tt3L40Zb0ORVVCLWeEAj87wzgI44VncGvrgFFg6h2mLvZLsW3x0 E58Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RU84YQAA; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w6sor5726775lfc.24.2018.12.19.13.34.21 for (Google Transport Security); Wed, 19 Dec 2018 13:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RU84YQAA; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=wZ8trlwQPC9hiGZKEv5EaYDHKPPRSKQ7DlpYkIOznGo=; b=RU84YQAA9ttAmCj5fwbw1hMbyAy79lr8StEuIYPs9nOgSexZa0zqGJhbGusOBhYRhl xvmpaIiQVWKWaisVJxT3EF8AjHPFUOPsMmvVf0xabzznRPYkn4Ka2csi12L5kF0hjOA2 /YZ4p7KgF6klxJT/Fv9A5bUND4Lp9BrQt1C9Cu+DXoFZTNgZshlgaPpXxwkXJnqUg9BL qrMHZK/pasAsW4YC3x1UFogxA456adKKOJHz1U7syC70Xu0ShrNdgy0ATa0ffanp/ZPa 3YqZPYKxBhicupwqEWngQsDdCleZgY4sTjVKRTlNdvj6EHnv6HhLFbg4pQZAERHbxUTH llTg== X-Google-Smtp-Source: AFSGD/XdC5giLSZrQt/Kv87Ghx67drqER+B1qjvWKaiMHLOdw8yx48gU4/ChW9agrJeuwYmr+pkViQ== X-Received: by 2002:a19:8d01:: with SMTP id p1mr12727200lfd.149.1545255261117; Wed, 19 Dec 2018 13:34:21 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:20 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] rodata_test: add verification for __wr_after_init Date: Wed, 19 Dec 2018 23:33:35 +0200 Message-Id: <20181219213338.26619-10-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The write protection of the __wr_after_init data can be verified with the same methodology used for const data. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- mm/rodata_test.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index e1349520b436..a669cf9f5a61 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -16,8 +16,23 @@ #define INIT_TEST_VAL 0xC3 +/* + * Note: __ro_after_init data is, for every practical effect, equivalent to + * const data, since they are even write protected at the same time; there + * is no need for separate testing. + * __wr_after_init data, otoh, is altered also after the write protection + * takes place and it cannot be exploitable for altering more permanent + * data. + */ + static const int rodata_test_data = INIT_TEST_VAL; +#ifdef CONFIG_PRMEM +static int wr_after_init_test_data __wr_after_init = INIT_TEST_VAL; +extern long __start_wr_after_init; +extern long __end_wr_after_init; +#endif + static bool test_data(char *data_type, const int *data, unsigned long start, unsigned long end) { @@ -59,7 +74,13 @@ static bool test_data(char *data_type, const int *data, void rodata_test(void) { - test_data("rodata", &rodata_test_data, - (unsigned long)&__start_rodata, - (unsigned long)&__end_rodata); + if (!test_data("rodata", &rodata_test_data, + (unsigned long)&__start_rodata, + (unsigned long)&__end_rodata)) + return; +#ifdef CONFIG_PRMEM + test_data("wr after init data", &wr_after_init_test_data, + (unsigned long)&__start_wr_after_init, + (unsigned long)&__end_wr_after_init); +#endif } From patchwork Wed Dec 19 21:33:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738177 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 6084814E5 for ; Wed, 19 Dec 2018 21:34:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 518D7286B2 for ; Wed, 19 Dec 2018 21:34:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45EEB286B4; Wed, 19 Dec 2018 21:34:39 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC9D8286B2 for ; Wed, 19 Dec 2018 21:34:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BC958E001F; Wed, 19 Dec 2018 16:34:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 16EBA8E001D; Wed, 19 Dec 2018 16:34:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 035D88E001F; Wed, 19 Dec 2018 16:34:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id 85D8C8E001D for ; Wed, 19 Dec 2018 16:34:28 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id k16-v6so2559650lji.5 for ; Wed, 19 Dec 2018 13:34:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=onhqh99dHd68Vfgq2Ii/Xo+yMcGU0hQwBlJKysnTxbUVzntpOE/RCFiM5lCdVuhBif wGhNHOCx6Q7/De20XRyZv/ktOo5koLesMPtpHAGhMcjlGbgfgNdnRH7PkcmXubPrx8g2 y5aUCmSlMB5eptvUbKJPSFPWL4wRLy7HiI8lSqSLL6IK623IkX2uXu1i4xXf4RKQTtY6 j21Nz9gKjicypekKkm3Dhp9mj7XiuLyATpr7kAf46rAS12Lxh1rmPXTNK9BcL/XwTvmN J+RdYWAQMsAvhk4WjcEhyyi1zBhvpowZFF18wDp86eNbMyP/COdMotb2HsqtdJxgHxle +YxQ== X-Gm-Message-State: AA+aEWYoszMm73N0/RlMaATRP01E2q1rQVzhoFY8eevJeIJcCQXJeLqw aTTVzbQOBCBrlzGWYTISJRqhexPikFOVWmjjteR7kRtMq54Cpc6+19hu7+OTJ+YLi6PjgjeXZOg oeqqiOvNlF+x9wHQFBoSpgqqvHY4p4mEBsKrF3o6MXiFIs5T79zSuEw27pzPAavlQ9W1zZ7vweb WsfQ4lQhsmONwa7jI3sgUf3HQF+P8a1DdcrkGHvJBQyYDix8Edy7S3oR/cyE+vaariPZMEry52z ZDibHMSMTuDkOJTMCo5qQjJyC7D0TAmsr5/tqB/urXb3O0rctyA9WxjNUp5pPoye7YgSPfNWKAt nM/J1qO3nD599BGfu/hymwSWGthhqIi04K+GuLpaCvJ0684AnNSgs8jTlEzWa6fWg8F/d7073eT b X-Received: by 2002:a19:a302:: with SMTP id m2mr14550152lfe.108.1545255267896; Wed, 19 Dec 2018 13:34:27 -0800 (PST) X-Received: by 2002:a19:a302:: with SMTP id m2mr14550116lfe.108.1545255266732; Wed, 19 Dec 2018 13:34:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255266; cv=none; d=google.com; s=arc-20160816; b=boxf7MIpHCdVv3cjJha6IlcZxiiU98agKjS+6UIWLboKPgZm2MoUWGBeGjdIkLc3h7 lhsu8QjmmwxSfzqpsGNIi+xRgR+K8XQJAniKublGe4xcNZ9anxO5YpWmFm15H9REIEzU j/PRofzHL+nAgFAvYSKodpN5YDygTwZZ57O1mVtBqf/p7nrKP+lQIDjUcl7pEPrcQeF0 DZ06d+YE6oMM8OU5o6dsxx1QwB9zOY26jHMh/vULEOhMiq7icDWwkC3OTp2i0VUfTv8x K3XJTYshYmt+aolfIKNZyb6P9+iRcyCsiLB8C9aLBn//8TfawgXs2M83VV8pCM2WjAWt 1vIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=XesSUlTfNAhNupmnml4OnRQd/d8bl8f9OR0jCW9DPWT8IRn+vjz7ZXuqYmN+xbQQ9T GoEgfC3II3NwQ7r5krFdSGzEpfcm2ui5Q2xPwHPGrTAMvKDEPn1KAgEmY1UcEPSgOyGA lnnuaL9ilW5VhC2HImQ0xyl9PyWk3W/SwedOOct0UlT6JoB3LNd48Jlg3jTK+1QuRb6A aEDv678yC+Op9vBszojUAA9Kjd0M+bBlbkDPbmokEdvDOMiqGrJljFfzzmmyoRVB20nD LVx5nTvpaERqx/IXTz6kKDm1EZlFbMm6WiyxGLg6cPH62c8cE2biaRHpD85eqRbX5pzA 8qeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vGTkPcUF; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x66-v6sor12365850ljb.20.2018.12.19.13.34.26 for (Google Transport Security); Wed, 19 Dec 2018 13:34:26 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vGTkPcUF; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=nF+ce+AsD/YO6oFhBzoP5bXERd0j3/JBWm1ePv97n+k=; b=vGTkPcUFo/MMtKaWdBnUN7Wr0yJwxwfs21G27pnVV2k1BB2gRhB1bK7E0cHhYbqIgf stDCnsHWMfyP+yrG6oDmTMF96qa/BaUh7n6LG+3tu8TfXBh5Wu8DfaY+PV6lNfvBRdKh hNQbHgauq8nMJyjwqmvZjnwDRCxA5mLVfzWQ0bVZJe+zeth1/NOc5HzIGqpMFr/Qrlqx aAsQZ/q+cAxCC45Usqy0Xty8HNLpuBvEXpaPgWZc396htU9HqMdTxdiPYyjkaNHn7myJ xkIvhC2HOtkTyU5OhrA1C4U6i8nYCJDolSU8uTM4BXBZOybG0Kkmw2kFOsIZCZuoWSro lNVQ== X-Google-Smtp-Source: AFSGD/Wy2ENV+x3psGq5BTNSnjgWTYu45qYohRv5i5VPwG4fDvqlbGM3fM6N3dl/AyW8xTUnzykvyA== X-Received: by 2002:a2e:4601:: with SMTP id t1-v6mr15007443lja.111.1545255266361; Wed, 19 Dec 2018 13:34:26 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:25 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] x86_64: __clear_user as case of __memset_user Date: Wed, 19 Dec 2018 23:33:38 +0200 Message-Id: <20181219213338.26619-13-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To avoid code duplication, re-use __memset_user(), when clearing user-space memory. The overhead should be minimal (2 extra register assignments) and outside of the writing loop. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/lib/usercopy_64.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index 84f8f8a20b30..ab6aabb62055 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -69,34 +69,7 @@ EXPORT_SYMBOL(memset_user); unsigned long __clear_user(void __user *addr, unsigned long size) { - long __d0; - might_fault(); - /* no memory constraint because it doesn't change any memory gcc knows - about */ - stac(); - asm volatile( - " testq %[size8],%[size8]\n" - " jz 4f\n" - "0: movq $0,(%[dst])\n" - " addq $8,%[dst]\n" - " decl %%ecx ; jnz 0b\n" - "4: movq %[size1],%%rcx\n" - " testl %%ecx,%%ecx\n" - " jz 2f\n" - "1: movb $0,(%[dst])\n" - " incq %[dst]\n" - " decl %%ecx ; jnz 1b\n" - "2:\n" - ".section .fixup,\"ax\"\n" - "3: lea 0(%[size1],%[size8],8),%[size8]\n" - " jmp 2b\n" - ".previous\n" - _ASM_EXTABLE_UA(0b, 3b) - _ASM_EXTABLE_UA(1b, 2b) - : [size8] "=&c"(size), [dst] "=&D" (__d0) - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr)); - clac(); - return size; + return __memset_user(addr, 0, size); } EXPORT_SYMBOL(__clear_user);