From 8b091debea9ae6f613d672a46f966278d84dafff Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 10 Feb 2022 11:06:25 -0800 Subject: [PATCH] LU-15420 uapi: avoid gcc-11 -Werror=stringop-overread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit GCC 11 warns about string and memory operations on fixed address: In function ‘strlen’, inlined from ‘changelog_rec_sname’ at include/uapi/linux/lustre/lustre_user.h:1981:19, inlined from ‘mdd_changelog_rec_ext_rename’ at lustre/mdd/mdd_dir.c:932:2, inlined from ‘mdd_changelog_ns_store’ at lustre/mdd/mdd_dir.c:1061:3: include/linux/fortify-string.h:25:33: error: ‘__builtin_strlen’ reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread] 25 | #define __underlying_strlen __builtin_strlen The reason is that we are looking for an address right after the end of the chanelog record header which gcc thinks is an overrun. Rework the code to allow us to index the memory right after the changelog record header. Also fix a long hidden bug in the lustre snmp code. Lustre-change: https://review.whamcloud.com/46319 Lustre-commit: TBD (from 0ae7f1196ba14df9a2354f0803eb75eea92cb1ee) Change-Id: I13479b9074a392330d39f01656b26f9e9a91a8ec Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/46498 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/uapi/linux/lustre/lustre_user.h | 28 +++++++++++++------------- lustre/tests/mpi/Makefile.am | 2 +- snmp/lustre-snmp.c | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 5d6fa40..c5ada6f 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -41,6 +41,16 @@ * * @{ */ +#ifndef __KERNEL__ +# define __USE_ISOC99 1 +# include +# include /* snprintf() */ +# include + +# define __USE_GNU 1 +# define __USE_XOPEN2K8 1 +# define FILEID_LUSTRE 0x97 /* for name_to_handle_at() (and llapi_fd2fid()) */ +#endif /* !__KERNEL__ */ #include #include @@ -52,14 +62,6 @@ #include #include -#ifndef __KERNEL__ -# define __USE_ISOC99 1 -# include -# include /* snprintf() */ -# include -# define FILEID_LUSTRE 0x97 /* for name_to_handle_at() (and llapi_fd2fid()) */ -#endif /* !__KERNEL__ */ - #if defined(__cplusplus) extern "C" { #endif @@ -1992,16 +1994,14 @@ static inline char *changelog_rec_name(const struct changelog_rec *rec) (enum changelog_rec_extra_flags)(cref & CLFE_SUPPORTED)); } -static inline __kernel_size_t changelog_rec_snamelen(const struct changelog_rec *rec) +static inline char *changelog_rec_sname(const struct changelog_rec *rec) { - return rec->cr_namelen - strlen(changelog_rec_name(rec)) - 1; + return strchrnul(changelog_rec_name(rec), '\0') + 1; } -static inline char *changelog_rec_sname(const struct changelog_rec *rec) +static inline __kernel_size_t changelog_rec_snamelen(const struct changelog_rec *rec) { - char *cr_name = changelog_rec_name(rec); - - return cr_name + strlen(cr_name) + 1; + return strlen(changelog_rec_sname(rec)); } /** diff --git a/lustre/tests/mpi/Makefile.am b/lustre/tests/mpi/Makefile.am index d64964e..7cc95af 100644 --- a/lustre/tests/mpi/Makefile.am +++ b/lustre/tests/mpi/Makefile.am @@ -1,5 +1,5 @@ # Lustre MPI test Makefile -AM_CFLAGS := -fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 +AM_CFLAGS := -fPIC -D_GNU_SOURCE -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 CC = @MPICC_WRAPPER@ diff --git a/snmp/lustre-snmp.c b/snmp/lustre-snmp.c index 3d8bcbc..603d343 100644 --- a/snmp/lustre-snmp.c +++ b/snmp/lustre-snmp.c @@ -713,7 +713,7 @@ void deinit_lustresnmp(void) { /* deregister ourselves with the agent */ unregister_mib(clusterFileSystems_variables_oid, sizeof(clusterFileSystems_variables_oid)/ - sizeof(clusterFileSystems_variables_oid)); + sizeof(clusterFileSystems_variables_oid[0])); terminate_trap_handler(); -- 1.8.3.1