]> www.infradead.org Git - users/hch/block.git/commitdiff
watch_queue: Make watch_sizeof() check record size
authorDavid Howells <dhowells@redhat.com>
Thu, 23 Jul 2020 10:52:08 +0000 (11:52 +0100)
committerDavid Howells <dhowells@redhat.com>
Mon, 27 Jul 2020 20:47:09 +0000 (21:47 +0100)
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

index 5e08db2adc31994c6e26264ccd67cd92ae686ff9..38e04c7a7951aad84ab689037d8dedf3528db351 100644 (file)
@@ -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