mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: Kees Cook <keescook@chromium.org>, jannh@google.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Yama: use READ_ONCE() when reading ptrace_scope
Date: Thu,  6 Sep 2018 16:29:35 +0200	[thread overview]
Message-ID: <20180906142935.230597-1-jannh@google.com> (raw)

ptrace_scope can be modified concurrently. To ensure that the compiler only
reads ptrace_scope once, use READ_ONCE() here. (In practice, at least the
version of gcc on my machine only generates a single read anyway, and it
seems unlikely that a compiler would do something different.)

This also serves as documentation for the reader.

Signed-off-by: Jann Horn <jannh@google.com>
---
 security/yama/yama_lsm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index ffda91a4a1aa..3b18e4455f53 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -362,7 +362,7 @@ static int yama_ptrace_access_check(struct task_struct *child,
 
 	/* require ptrace target be a child of ptracer on attach */
 	if (mode & PTRACE_MODE_ATTACH) {
-		switch (ptrace_scope) {
+		switch (READ_ONCE(ptrace_scope)) {
 		case YAMA_SCOPE_DISABLED:
 			/* No additional restrictions. */
 			break;
@@ -404,7 +404,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
 	int rc = 0;
 
 	/* Only disallow PTRACE_TRACEME on more aggressive settings. */
-	switch (ptrace_scope) {
+	switch (READ_ONCE(ptrace_scope)) {
 	case YAMA_SCOPE_CAPABILITY:
 		if (!has_ns_capability(parent, current_user_ns(), CAP_SYS_PTRACE))
 			rc = -EPERM;
-- 
2.19.0.rc1.350.ge57e33dbd1-goog


                 reply	other threads:[~2018-09-06 14:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180906142935.230597-1-jannh@google.com \
    --to=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®