From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: dhowells@redhat.com
Cc: viro@zeniv.linux.org.uk, tytso@mit.edu, khazhy@google.com,
adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
linux-fsdevel@vger.kernel.org, kernel@collabora.com,
Miklos Szeredi <mszeredi@redhat.com>,
Gabriel Krisman Bertazi <krisman@collabora.com>
Subject: [PATCH RFC 1/7] watch_queue: Make watch_sizeof() check record size
Date: Tue, 20 Oct 2020 15:15:37 -0400 [thread overview]
Message-ID: <20201020191543.601784-2-krisman@collabora.com> (raw)
In-Reply-To: <20201020191543.601784-1-krisman@collabora.com>
From: David Howells <dhowells@redhat.com>
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>
[Rebase to 5.10]
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.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 c994d1b2cdba..f1086d12cd03 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; \
+ })
#else
static inline int watch_queue_init(struct pipe_inode_info *pipe)
--
2.28.0
next prev parent reply other threads:[~2020-10-20 19:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 19:15 [PATCH RFC 0/7] Superblock notifications Gabriel Krisman Bertazi
2020-10-20 19:15 ` Gabriel Krisman Bertazi [this message]
2020-10-20 19:15 ` [PATCH RFC 2/7] security: Add hooks to rule on setting a watch for superblock Gabriel Krisman Bertazi
2020-10-20 19:15 ` [PATCH RFC 3/7] watch_queue: Support a text field at the end of the notification Gabriel Krisman Bertazi
2020-10-20 19:15 ` [PATCH RFC 4/7] vfs: Add superblock notifications Gabriel Krisman Bertazi
2020-10-20 19:15 ` [PATCH RFC 5/7] vfs: Include origin of the SB error notification Gabriel Krisman Bertazi
2020-10-20 19:15 ` [PATCH RFC 6/7] fs: Add more superblock error subtypes Gabriel Krisman Bertazi
2020-10-21 15:21 ` Theodore Y. Ts'o
2020-10-20 19:15 ` [PATCH RFC 7/7] ext4: Implement SB error notification through watch_sb Gabriel Krisman Bertazi
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=20201020191543.601784-2-krisman@collabora.com \
--to=krisman@collabora.com \
--cc=adilger.kernel@dilger.ca \
--cc=dhowells@redhat.com \
--cc=kernel@collabora.com \
--cc=khazhy@google.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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