Skip to content

Commit b9b410c

Browse files
committed
fanotify: Drop use of flex array in fanotify_fh
We use flex array 'buf' in fanotify_fh to contain the file handle content. However the buffer is not a proper flex array. It has a preconfigured fixed size. Furthermore if fixed size is not big enough, we use external separately allocated buffer. Hence don't pretend buf is a flex array since we have to use special accessors anyway and instead just modify the accessors to do the pointer math without flex array. This fixes warnings that flex array is not the last struct member in fanotify_fid_event or fanotify_error_event. Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Amir Goldstein <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent e48e99b commit b9b410c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode,
415415
{
416416
int dwords, type = 0;
417417
char *ext_buf = NULL;
418-
void *buf = fh->buf;
418+
void *buf = fh + 1;
419419
int err;
420420

421421
fh->type = FILEID_ROOT;

fs/notify/fanotify/fanotify.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum {
2525
* stored in either the first or last 2 dwords.
2626
*/
2727
#define FANOTIFY_INLINE_FH_LEN (3 << 2)
28-
#define FANOTIFY_FH_HDR_LEN offsetof(struct fanotify_fh, buf)
28+
#define FANOTIFY_FH_HDR_LEN sizeof(struct fanotify_fh)
2929

3030
/* Fixed size struct for file handle */
3131
struct fanotify_fh {
@@ -34,7 +34,6 @@ struct fanotify_fh {
3434
#define FANOTIFY_FH_FLAG_EXT_BUF 1
3535
u8 flags;
3636
u8 pad;
37-
unsigned char buf[];
3837
} __aligned(4);
3938

4039
/* Variable size struct for dir file handle + child file handle + name */
@@ -92,7 +91,7 @@ static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh)
9291
BUILD_BUG_ON(FANOTIFY_FH_HDR_LEN % 4);
9392
BUILD_BUG_ON(__alignof__(char *) - 4 + sizeof(char *) >
9493
FANOTIFY_INLINE_FH_LEN);
95-
return (char **)ALIGN((unsigned long)(fh->buf), __alignof__(char *));
94+
return (char **)ALIGN((unsigned long)(fh + 1), __alignof__(char *));
9695
}
9796

9897
static inline void *fanotify_fh_ext_buf(struct fanotify_fh *fh)
@@ -102,7 +101,7 @@ static inline void *fanotify_fh_ext_buf(struct fanotify_fh *fh)
102101

103102
static inline void *fanotify_fh_buf(struct fanotify_fh *fh)
104103
{
105-
return fanotify_fh_has_ext_buf(fh) ? fanotify_fh_ext_buf(fh) : fh->buf;
104+
return fanotify_fh_has_ext_buf(fh) ? fanotify_fh_ext_buf(fh) : fh + 1;
106105
}
107106

108107
static inline int fanotify_info_dir_fh_len(struct fanotify_info *info)
@@ -278,7 +277,7 @@ static inline void fanotify_init_event(struct fanotify_event *event,
278277
#define FANOTIFY_INLINE_FH(name, size) \
279278
struct { \
280279
struct fanotify_fh name; \
281-
/* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \
280+
/* Space for filehandle - access with fanotify_fh_buf() */ \
282281
unsigned char _inline_fh_buf[size]; \
283282
}
284283

0 commit comments

Comments
 (0)