From patchwork Fri May 19 01:19:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13247583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97C29C7EE2C for ; Fri, 19 May 2023 01:19:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2259E280003; Thu, 18 May 2023 21:19:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B13D280001; Thu, 18 May 2023 21:19:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF4BD280003; Thu, 18 May 2023 21:19:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE5B5280001 for ; Thu, 18 May 2023 21:19:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B45D4AE41A for ; Fri, 19 May 2023 01:19:32 +0000 (UTC) X-FDA: 80805246984.18.4163B3F Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf05.hostedemail.com (Postfix) with ESMTP id CDB3E100012 for ; Fri, 19 May 2023 01:19:30 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JWIfslA4; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684459170; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DlYfhs3BTQ2EJ5c00OoF7xAAokRQfPc4lQTpfzHm9OE=; b=cIKgdc//jN1W1MCSe6c0vcHjxB0U9gqRWsUufaNwJNsIB1MB0GuZcnM6Sj5WALzgVc6na/ dwb6tnPZqHd4L07+Qcjj33/+6RyN2psiE8ObPWpybvBeKlmLzk1q4HsYjmX2ttxIrioDxo 9tjOjrI95Z/pmDCBfYSPaKd1Q5YxQDo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JWIfslA4; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684459170; a=rsa-sha256; cv=none; b=eSOPJs7MxALPLnykAjX07QK5ysmJHB+45WrPiHYEXirJI1xekLPRTcBUr16YDVp6SZsj35 nj+5VxaZ0y7Gt5OndgpPxOLH0VFfvoOK+qPsOJXLb8HH9BTjAOKcreCiMLCZNOVkTUyFew 7lTI8jWXrSL70Rw7wNllfoBgp0gO00Y= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-64d2981e3abso669542b3a.1 for ; Thu, 18 May 2023 18:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684459169; x=1687051169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DlYfhs3BTQ2EJ5c00OoF7xAAokRQfPc4lQTpfzHm9OE=; b=JWIfslA4UKDBw1Mp583btzlGGK8G9E6xpS7M8yt3iOyE0agyVlu+KO5Lxq4vpucXSU HH1YA4BQeb7OL6OLVkoix4UxlcxXNVOrDy2c5gWBw82vyYqfMb8tY9sDkBb9j+Na0b8j 0kO3Cd+a0jrUOyQcvN7J2vDvvbkTYN/CiGCqY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684459169; x=1687051169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DlYfhs3BTQ2EJ5c00OoF7xAAokRQfPc4lQTpfzHm9OE=; b=TphhJ/JJnh3elMzf6JkXu7+UAPc4Cia8W8zq3AE0jRbK5C0Dt8lUnsBbaTSQxduZZo UcKvdMJ3f/+Vyza+GrwdCXAoG1AHb/nQEu0FztS7f8WKfgvEfKbjiQ2yUbm0SDsEmh0o JpeCEbUW5TwzVaReTOPtjcYuk0XkfQAK1ybWNZaB/BP1B6fq/MY6q8LHOwm5j13z3Yf8 DlAmUwjnb+T+NGShIOe+rbVlXVuKtVJhI/SCGf1PfIalm1GngLi2Zby4iLcQVFF7yMaF i+ItWnXey0ll4K6XJlp2HJYPH8+pa5x4+5Ix3oE+7VvktyGeL22fyTnbTIiH7O+RZyep RmOg== X-Gm-Message-State: AC+VfDwtFkiPh19WTBetTN7/Pjv7hfbOCkdlaZwvilMfIYdphZxorN0g M2uc/FGEWN6icZL9YWVx9F2Bdg== X-Google-Smtp-Source: ACHHUZ65BMUPG6NH0sSEE5yDD+qKd1DPXj0Iug+5r1nNE9fAXNvkKS48swgrqtg3LFDKz96p8HSxUA== X-Received: by 2002:a05:6a20:8422:b0:ef:205f:8184 with SMTP id c34-20020a056a20842200b000ef205f8184mr425525pzd.13.1684459169739; Thu, 18 May 2023 18:19:29 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id c24-20020a62e818000000b00643864d03dfsm1960424pfi.171.2023.05.18.18.19.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 May 2023 18:19:29 -0700 (PDT) From: jeffxu@chromium.org To: dave.hansen@intel.com, luto@kernel.org, jorgelo@chromium.org, keescook@chromium.org, groeck@chromium.org, jannh@google.com, sroettger@google.com Cc: akpm@linux-foundation.org, jeffxu@google.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH v1 3/6] PKEY: Apply PKEY_ENFORCE_API to mprotect Date: Fri, 19 May 2023 01:19:11 +0000 Message-ID: <20230519011915.846407-4-jeffxu@chromium.org> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog In-Reply-To: <20230519011915.846407-1-jeffxu@chromium.org> References: <20230519011915.846407-1-jeffxu@chromium.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: az3qx86sphmaw95nhzq91djchgwh7mya X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CDB3E100012 X-HE-Tag: 1684459170-22946 X-HE-Meta: U2FsdGVkX19HVPN9wfmKL9cZ9qYZzM2WEHpxlGZwwSNBmjAjRe7Si41bnwdPjGPoz3PcrDTNwV++ZwuG8uDKKBMUK/l2sxhFAG0oFz+JuLvGV9SJutlVDPPkfbQFQ9kMbB1sVsRLOA78b1Oe8vANtxns+ETp7mWgIvVQVpwStJIc09Q3YgGvYAxAf9mRxGk0NVFGVcoxtoCDPj07udCuOE5dJr2bgJlPRd3H8xW/xxP2DkaMao9yDdERfHmgsQ3qK534uVxhosB++OKc+YfsU/S9ZXKxQALUuDoLo4l04dSHqscU5KU44+yHUEpr/XF87w1u5Rl1SZ3PdUS10sCNQu9uCRBBauSC4PYRzljh+36df0Q5KqzUGqh5qsIUMZ/m9/0JFfw3ki7cw9ChJ0N5pTXKEjJpAqTC3su5fq8ovd3H4rMwqG1jqcOu5Na1NCsZVpZMZ96CIZC+rGxOW1YWrV1UlRt5xsk/wVrKCDlOfkDNKWfAIst9smCRNybjZlH+ffCOUAac8+wUdEJML+yV07GyvS0Vc4q/0Y0kgGAHNx4NSrhPzjJHvr/oskEIQRlsXyQhbFL5JJTQzQtMa/SwU0OdBYvwTEi/Mg5j4TvswR3LqojoQIj6pSdXJIj6DimkO0Y3hIXbxs552tv1PqlBoqq6Jx7tJkSWE2yH7G+8OT76DlzyCqsDPA0i9NG7XJIoOo+ZRVM1opJZ8jxCNcT28ySjwTp5u8IAGxXjTPTVMfY/f+tLGL9IYD7bZDjX7WUwlQcUxZA0JdB32Z1ANEUenwVwBxVbqoNffmT5QQKMSqchOnlZUmsv7A4e+KRacXWeQsSEAGLtRpsmg+/FxJStjuW/N7m7pYT+cW330GTX7+0KD28mcd3loOwnLHP3S7nQOzvslByeoXXhQZ+I8zw+NnUBkO9PpTPwBD6s3uT5wF57PWIckTpuUeaj+c1O+BXVaoKzNif5bYbD0yuzyUF Rixa7ndL t0Js0fzqV7NwZyQoTiNSyU9XmUA9Xg3hgoztM9PBvI+LdTcN6naQSolwxfdw2yoZyqra2f4lPgvIbMVSJyjtkyed0pISaS8g6XSplCGfaMEui1tgr+ljjCx6WolpVpJbedIdeoKSnK20u2cgB49frKu49p4N8+LuXgotyWdJN3wRur+WhnlcP0vVdb++qqsF2QN9KeS/idOn4qPuP3ePOlesJ8qGs3R7nVvIQPkdmRMlKJJGmFb7F+kgFxjItZhIewjqsUQllXrN2DXSjycwsaOHTtT5rxTrIqRNFX12z0UzlMZt13SzjoLNn+I+KV17/K4ZbgWYO8n7VmLnvO4xi12SlRKb5/bYk7aX9qN51PY0vppc/eyi6/nGda54mqC1z+IRUpfd4Dmub+mzXA4IdJ1zCemwm3BBocPwK 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: From: Jeff Xu This patch enables PKEY_ENFORCE_API for the mprotect and mprotect_pkey syscalls. Signed-off-by: Jeff Xu --- mm/mprotect.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 8a68fdca8487..1db30b8baac3 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -794,6 +794,17 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } } + /* + * arch_check_pkey_enforce_api checks if current thread + * has the PKEY permission to modify the memory mapping. + * Note: this should only apply to the cases that do_mprotect_pkey + * is called from syscall entry. Ref. to munmap for other cases. + */ + if (arch_check_pkey_enforce_api(current->mm, start, end) < 0) { + error = -EACCES; + goto out; + } + prev = vma_prev(&vmi); if (start > vma->vm_start) prev = vma;