[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <159645999738.1779777.4882634293182825979.stgit@warthog.procyon.org.uk>
Date: Mon, 03 Aug 2020 14:06:37 +0100
From: David Howells <dhowells@...hat.com>
To: viro@...iv.linux.org.uk
Cc: Miklos Szeredi <mszeredi@...hat.com>, dhowells@...hat.com,
torvalds@...ux-foundation.org, casey@...aufler-ca.com,
sds@...ho.nsa.gov, nicolas.dichtel@...nd.com, raven@...maw.net,
christian@...uner.io, jlayton@...hat.com, kzak@...hat.com,
mszeredi@...hat.com, linux-api@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-security-module@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 2/5] watch_queue: Make watch_sizeof() check record size [ver
#2]
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@...hat.com>
Signed-off-by: David Howells <dhowells@...hat.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
Powered by blists - more mailing lists