public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: glider@google.com
To: tkjos@google.com, keescook@chromium.org,
	gregkh@linuxfoundation.org, arve@android.com, mingo@redhat.com
Cc: dvyukov@google.com, jannh@google.com, devel@driverdev.osuosl.org,
	peterz@infradead.org, linux-kernel@vger.kernel.org,
	Alexander Potapenko <glider@google.com>
Subject: [PATCH v2 3/3] sched/wait: avoid double initialization in ___wait_event()
Date: Mon,  2 Mar 2020 14:04:30 +0100	[thread overview]
Message-ID: <20200302130430.201037-3-glider@google.com> (raw)
In-Reply-To: <20200302130430.201037-1-glider@google.com>

With CONFIG_INIT_STACK_ALL enabled, the local __wq_entry is initialized
twice. Because Clang is currently unable to optimize the automatic
initialization away (init_wait_entry() is defined in another translation
unit), remove it with the __no_initialize annotation.

Cc: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alexander Potapenko <glider@google.com>

---
 v2:
  - changed __do_not_initialize to __no_initialize as requested by Kees
    Cook
---
 drivers/android/binder.c | 4 ++--
 include/linux/wait.h     | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index a59871532ff6b..66984e7c33094 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -4827,7 +4827,7 @@ static int binder_ioctl_write_read(struct file *filp,
 	struct binder_proc *proc = filp->private_data;
 	unsigned int size = _IOC_SIZE(cmd);
 	void __user *ubuf = (void __user *)arg;
-	struct binder_write_read bwr __no_initialize;
+	struct binder_write_read bwr;
 
 	if (size != sizeof(struct binder_write_read)) {
 		ret = -EINVAL;
@@ -5026,7 +5026,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			goto err;
 		break;
 	case BINDER_SET_MAX_THREADS: {
-		int max_threads;
+		int max_threads __no_initialize;
 
 		if (copy_from_user(&max_threads, ubuf,
 				   sizeof(max_threads))) {
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 3283c8d021377..b52a9bb2c7727 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -262,7 +262,8 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
 #define ___wait_event(wq_head, condition, state, exclusive, ret, cmd)		\
 ({										\
 	__label__ __out;							\
-	struct wait_queue_entry __wq_entry;					\
+	/* Unconditionally initialized by init_wait_entry(). */			\
+	struct wait_queue_entry __wq_entry __no_initialize;			\
 	long __ret = ret;	/* explicit shadow */				\
 										\
 	init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0);	\
-- 
2.25.0.265.gbab2e86ba0-goog


  parent reply	other threads:[~2020-03-02 13:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02 13:04 [PATCH v2 1/3] compiler.h: define __no_initialize glider
2020-03-02 13:04 ` [PATCH v2 2/3] binder: do not initialize locals passed to copy_from_user() glider
2020-03-02 13:09   ` Joe Perches
2020-03-02 13:25     ` Alexander Potapenko
2020-03-02 13:52       ` Dan Carpenter
2020-03-02 13:58       ` Joe Perches
2020-03-02 18:17         ` Alexander Potapenko
2020-03-02 18:31           ` Jann Horn
2020-03-05  9:03             ` Rasmus Villemoes
2020-03-05 12:45               ` Jann Horn
2020-03-06  2:29               ` Al Viro
2020-03-02 18:50           ` Joe Perches
2020-03-03  9:14             ` Alexander Potapenko
2020-03-03  9:38               ` Dan Carpenter
2020-03-03 13:56                 ` Joe Perches
2020-03-03 14:15                   ` Dan Carpenter
2020-03-04 18:13                 ` Kees Cook
2020-03-05  8:07                   ` Dan Carpenter
2020-03-05  8:26                     ` Kees Cook
2020-03-05  8:33                       ` Alexander Potapenko
2020-03-02 17:38   ` Greg KH
2020-03-02 18:28     ` Alexander Potapenko
2020-03-02 13:04 ` glider [this message]
2020-03-02 16:56   ` [PATCH v2 3/3] sched/wait: avoid double initialization in ___wait_event() Todd Kjos
2020-03-02 18:03     ` Alexander Potapenko
2020-03-02 18:39       ` Greg Kroah-Hartman

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=20200302130430.201037-3-glider@google.com \
    --to=glider@google.com \
    --cc=arve@android.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tkjos@google.com \
    /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