Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: viro@zeniv.linux.org.uk
Cc: Miklos Szeredi <mszeredi@redhat.com>,
	dhowells@redhat.com, torvalds@linux-foundation.org,
	casey@schaufler-ca.com, sds@tycho.nsa.gov,
	nicolas.dichtel@6wind.com, raven@themaw.net,
	christian@brauner.io, jlayton@redhat.com, kzak@redhat.com,
	mszeredi@redhat.com, linux-api@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] watch_queue: Make watch_sizeof() check record size [ver #2]
Date: Mon, 03 Aug 2020 14:06:37 +0100	[thread overview]
Message-ID: <159645999738.1779777.4882634293182825979.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <159645997768.1779777.8286723139418624756.stgit@warthog.procyon.org.uk>

Make watch_sizeof() give a build error if the size of the struct won't fit
into the size field in the header.

Reported-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 include/linux/watch_queue.h |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h
index 5e08db2adc31..38e04c7a7951 100644
--- a/include/linux/watch_queue.h
+++ b/include/linux/watch_queue.h
@@ -120,7 +120,12 @@ static inline void remove_watch_list(struct watch_list *wlist, u64 id)
  * watch_sizeof - Calculate the information part of the size of a watch record,
  * given the structure size.
  */
-#define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT)
+#define watch_sizeof(STRUCT) \
+	({								\
+		size_t max = WATCH_INFO_LENGTH >> WATCH_INFO_LENGTH__SHIFT; \
+		BUILD_BUG_ON(sizeof(STRUCT) > max);			\
+		sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT;		\
+	})
 
 #endif
 



  parent reply	other threads:[~2020-08-03 13:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-03 13:06 [PATCH 0/5] Mount notifications " David Howells
2020-08-03 13:06 ` [PATCH 1/5] watch_queue: Limit the number of watches a user can hold " David Howells
2020-08-03 13:06 ` David Howells [this message]
2020-08-03 13:06 ` [PATCH 3/5] watch_queue: Add security hooks to rule on setting mount watches " David Howells
2020-08-03 13:06 ` [PATCH 4/5] watch_queue: Implement mount topology and attribute change notifications " David Howells
2020-08-03 13:07 ` [PATCH 5/5] watch_queue: sample: Display mount tree " David Howells
2020-08-03 13:22 ` [PATCH 0/5] Mount " David Howells

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=159645999738.1779777.4882634293182825979.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=casey@schaufler-ca.com \
    --cc=christian@brauner.io \
    --cc=jlayton@redhat.com \
    --cc=kzak@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=nicolas.dichtel@6wind.com \
    --cc=raven@themaw.net \
    --cc=sds@tycho.nsa.gov \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH 2/5] watch_queue: Make watch_sizeof() check record size [ver #2]' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).