From 03ddd706d99b09790cb6251c338d4d246292cd06 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Jun 2023 02:19:41 +0000 Subject: [PATCH] LU-16518 misc: fix clang build errors Fix several format security errors by explicitly giving the format to the affected functions. A write test in badareaio attempts to write more than 2,147,479,552 bytes. The write will never write that much, so reduce the size of the write to make the test useful. Explicitly cast ll_nfs_get_name_filldir as a filldir_t and NR_WRITEBACK as a zone_stat_item. This silences some implicit cast errors. These casts can likely be removed when older kernel support is dropped. Refactor some code to avoid strncat, which was being used incorrectly anyway. Adjust some variables to use more appropriate types. Inline some functions which are only sometimes used. Remove a LASSERTF that will never trigger, since u32 is always smaller than IDIF_MAX_OID. Signed-off-by: Timothy Day Change-Id: I3962611de7d012e544636248353c072c9f9c9830 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50332 Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/include/lustre_log.h | 4 ++-- lustre/lfsck/lfsck_lib.c | 2 +- lustre/llite/llite_nfs.c | 2 +- lustre/lod/lod_object.c | 2 +- lustre/mdd/mdd_device.c | 2 +- lustre/mgc/mgc_request.c | 13 ++++++------- lustre/obdclass/genops.c | 4 ++-- lustre/obdclass/llog_ioctl.c | 4 ++-- lustre/osc/osc_lock.c | 2 +- lustre/osc/osc_page.c | 7 +++++-- lustre/osp/lwp_dev.c | 2 +- lustre/osp/osp_precreate.c | 4 ---- lustre/quota/qsd_lib.c | 15 ++++++++------- lustre/target/update_records.c | 2 +- lustre/tests/badarea_io.c | 8 ++++---- 15 files changed, 36 insertions(+), 37 deletions(-) diff --git a/lustre/include/lustre_log.h b/lustre/include/lustre_log.h index 14e5668..248a32b 100644 --- a/lustre/include/lustre_log.h +++ b/lustre/include/lustre_log.h @@ -195,8 +195,8 @@ int llog_sync(struct llog_ctxt *ctxt, struct obd_export *exp, int flags); struct obd_ioctl_data; int llog_print_cb(const struct lu_env *env, struct llog_handle *handle, struct llog_rec_hdr *rec, void *data); -int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd, - struct obd_ioctl_data *data); +int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, + unsigned int cmd, struct obd_ioctl_data *data); int llog_catalog_list(const struct lu_env *env, struct dt_device *d, int count, struct obd_ioctl_data *data, const struct lu_fid *fid); diff --git a/lustre/lfsck/lfsck_lib.c b/lustre/lfsck/lfsck_lib.c index 3713f15b4..c2115a3 100644 --- a/lustre/lfsck/lfsck_lib.c +++ b/lustre/lfsck/lfsck_lib.c @@ -2533,7 +2533,7 @@ int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com, if (IS_ERR(lta)) RETURN(PTR_ERR(lta)); - task = kthread_run(lfsck_assistant_engine, lta, lad->lad_name); + task = kthread_run(lfsck_assistant_engine, lta, "%s", lad->lad_name); if (IS_ERR(task)) { rc = PTR_ERR(task); CERROR("%s: cannot start LFSCK assistant thread for %s: " diff --git a/lustre/llite/llite_nfs.c b/lustre/llite/llite_nfs.c index 5c16937..4167e0f 100644 --- a/lustre/llite/llite_nfs.c +++ b/lustre/llite/llite_nfs.c @@ -266,7 +266,7 @@ static int ll_get_name(struct dentry *dentry, char *name, struct dentry *child) .lgd_name = name, .lgd_fid = ll_i2info(child->d_inode)->lli_fid, #ifdef HAVE_DIR_CONTEXT - .ctx.actor = ll_nfs_get_name_filldir, + .ctx.actor = (filldir_t)ll_nfs_get_name_filldir, #endif .lgd_found = 0, }; diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 8404932..e36d9af 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -5538,7 +5538,7 @@ static void lod_striping_from_default(struct lod_object *lo, &lds->lds_def_comp_entries[i]; CDEBUG(D_LAYOUT, - "inherit "DFID" file layout from default: flags=%#x size=%hu nr=%u offset=%u pattern=%#x pool=%s\n", + "inherit "DFID" file layout from default: flags=%#x size=%u nr=%u offset=%u pattern=%#x pool=%s\n", PFID(lu_object_fid(&lo->ldo_obj.do_lu)), def_comp->llc_flags, def_comp->llc_stripe_size, diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 56ade2e..57242b2 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -2408,7 +2408,7 @@ int mdd_generic_thread_start(struct mdd_generic_thread *thread, thread->mgt_abort = false; thread->mgt_init = true; - task = kthread_run(func, thread, name); + task = kthread_run(func, thread, "%s", name); if (IS_ERR(task)) { complete(&thread->mgt_finished); return PTR_ERR(task); diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 48dad3f..eb07035 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -262,6 +262,7 @@ config_recover_log_add(struct obd_device *obd, char *fsname, { struct config_llog_instance lcfg = *cfg; struct config_llog_data *cld; + bool is_server = IS_SERVER(s2lsi(sb)); char logname[32]; #ifdef HAVE_SERVER_SUPPORT @@ -277,14 +278,12 @@ config_recover_log_add(struct obd_device *obd, char *fsname, */ LASSERT(strlen(fsname) < sizeof(logname) / 2); strncpy(logname, fsname, sizeof(logname)); - if (IS_SERVER(s2lsi(sb))) { /* mdt */ - LASSERT(lcfg.cfg_instance == 0); + + LASSERT(is_server ? lcfg.cfg_instance == 0 : lcfg.cfg_instance != 0); + if (is_server) lcfg.cfg_instance = ll_get_cfg_instance(sb); - strncat(logname, "-mdtir", sizeof(logname)); - } else { - LASSERT(lcfg.cfg_instance != 0); - strncat(logname, "-cliir", sizeof(logname)); - } + scnprintf(logname, sizeof(logname), "%s-%s", fsname, + is_server ? "mdtir" : "cliir"); cld = do_config_log_add(obd, logname, MGS_CFG_T_RECOVER, &lcfg, sb); return cld; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 379e0bf..75703c0 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -2083,7 +2083,7 @@ int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max) if (max > OBD_MAX_RIF_MAX || max < 1) return -ERANGE; - CDEBUG(D_INFO, "%s: max = %hu max_mod = %u rif = %u\n", + CDEBUG(D_INFO, "%s: max = %u max_mod = %u rif = %u\n", cli->cl_import->imp_obd->obd_name, max, cli->cl_max_mod_rpcs_in_flight, cli->cl_max_rpcs_in_flight); @@ -2156,7 +2156,7 @@ int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max) */ if (max >= cli->cl_max_rpcs_in_flight) { CDEBUG(D_INFO, - "%s: increasing max_rpcs_in_flight=%hu to allow larger max_mod_rpcs_in_flight=%u\n", + "%s: increasing max_rpcs_in_flight=%u to allow larger max_mod_rpcs_in_flight=%u\n", cli->cl_import->imp_obd->obd_name, max + 1, max); obd_set_max_rpcs_in_flight(cli, max + 1); } diff --git a/lustre/obdclass/llog_ioctl.c b/lustre/obdclass/llog_ioctl.c index 070b221..2b70f7f 100644 --- a/lustre/obdclass/llog_ioctl.c +++ b/lustre/obdclass/llog_ioctl.c @@ -349,8 +349,8 @@ static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle, RETURN(rc); } -int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd, - struct obd_ioctl_data *data) +int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, + unsigned int cmd, struct obd_ioctl_data *data) { struct llog_logid logid; int rc = 0; diff --git a/lustre/osc/osc_lock.c b/lustre/osc/osc_lock.c index 38e6ade..91f9a36 100644 --- a/lustre/osc/osc_lock.c +++ b/lustre/osc/osc_lock.c @@ -64,7 +64,7 @@ static struct ldlm_lock *osc_handle_ptr(struct lustre_handle *handle) /** * Invariant that has to be true all of the time. */ -static int osc_lock_invariant(struct osc_lock *ols) +static inline int osc_lock_invariant(struct osc_lock *ols) { struct ldlm_lock *lock = osc_handle_ptr(&ols->ols_handle); struct ldlm_lock *olock = ols->ols_dlmlock; diff --git a/lustre/osc/osc_page.c b/lustre/osc/osc_page.c index 6e491d5..be587bc 100644 --- a/lustre/osc/osc_page.c +++ b/lustre/osc/osc_page.c @@ -887,6 +887,7 @@ void osc_lru_unreserve(struct client_obd *cli, unsigned long npages) #ifdef HAVE_NR_UNSTABLE_NFS /* Old kernels use a separate counter for unstable pages, * newer kernels treat them like any other writeback. + * (see Linux commit: v5.7-467-g8d92890bd6b8) */ #define NR_WRITEBACK NR_UNSTABLE_NFS #endif @@ -919,7 +920,8 @@ static inline void unstable_page_accounting(struct ptlrpc_bulk_desc *desc, } if (count > 0) { - mod_zone_page_state(zone, NR_WRITEBACK, + mod_zone_page_state(zone, + (enum zone_stat_item)NR_WRITEBACK, factor * count); count = 0; } @@ -927,7 +929,8 @@ static inline void unstable_page_accounting(struct ptlrpc_bulk_desc *desc, ++count; } if (count > 0) - mod_zone_page_state(zone, NR_WRITEBACK, factor * count); + mod_zone_page_state(zone, (enum zone_stat_item)NR_WRITEBACK, + factor * count); } static inline void add_unstable_page_accounting(struct ptlrpc_bulk_desc *desc, diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index bb76ff0..fd825c6 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -449,7 +449,7 @@ static void lwp_notify_users(struct obd_export *exp) return; } - task = kthread_create(lwp_notify_main, exp, name); + task = kthread_create(lwp_notify_main, exp, "%s", name); if (IS_ERR(task)) { CERROR("Failed to start LWP notify thread:%s. %lu\n", name, PTR_ERR(task)); diff --git a/lustre/osp/osp_precreate.c b/lustre/osp/osp_precreate.c index cabc772..6f5afb2 100644 --- a/lustre/osp/osp_precreate.c +++ b/lustre/osp/osp_precreate.c @@ -978,10 +978,6 @@ static int osp_precreate_cleanup_orphans(struct lu_env *env, * This empties the pre-creation pool and effectively blocks any new * reservations. */ - LASSERTF(fid_oid(&d->opd_pre_last_created_fid) <= IDIF_MAX_OID, - "%s: last_created_fid "DFID" > %llu\n", - d->opd_obd->obd_name, PFID(&d->opd_pre_last_created_fid), - IDIF_MAX_OID); d->opd_pre_used_fid = d->opd_pre_last_created_fid; d->opd_pre_create_slow = 0; if ((body->oa.o_valid & OBD_MD_FLSIZE) && body->oa.o_size) diff --git a/lustre/quota/qsd_lib.c b/lustre/quota/qsd_lib.c index e29a5a7..2d27fab 100644 --- a/lustre/quota/qsd_lib.c +++ b/lustre/quota/qsd_lib.c @@ -132,20 +132,21 @@ LPROC_SEQ_FOPS_RO(qsd_state); static int qsd_enabled_seq_show(struct seq_file *m, void *data) { - struct qsd_instance *qsd = m->private; - char enabled[5]; + struct qsd_instance *qsd = m->private; + char enabled[5] = ""; + int types = 0; LASSERT(qsd != NULL); memset(enabled, 0, sizeof(enabled)); if (qsd_type_enabled(qsd, USRQUOTA)) - strncat(enabled, "u", sizeof(enabled) - strlen(enabled)); + enabled[types++] = 'u'; if (qsd_type_enabled(qsd, GRPQUOTA)) - strncat(enabled, "g", sizeof(enabled) - strlen(enabled)); + enabled[types++] = 'g'; if (qsd_type_enabled(qsd, PRJQUOTA)) - strncat(enabled, "p", sizeof(enabled) - strlen(enabled)); - if (strlen(enabled) == 0) - strncat(enabled, "none", sizeof(enabled) - strlen(enabled)); + enabled[types++] = 'p'; + if (!types) + strncpy(enabled, "none", 4); seq_printf(m, "%s\n", enabled); return 0; diff --git a/lustre/target/update_records.c b/lustre/target/update_records.c index cec4374..7184a9e 100644 --- a/lustre/target/update_records.c +++ b/lustre/target/update_records.c @@ -236,7 +236,7 @@ static int update_records_update_pack(const struct lu_env *env, op->uop_params_off[i] = index; } - CDEBUG(D_INFO, "%huth "DFID" %s param_count = %u\n", + CDEBUG(D_INFO, "%uth "DFID" %s param_count = %u\n", *op_count, PFID(fid), update_op_str(op_type), *param_count); *op_count = *op_count + 1; diff --git a/lustre/tests/badarea_io.c b/lustre/tests/badarea_io.c index a46b598..663c881 100644 --- a/lustre/tests/badarea_io.c +++ b/lustre/tests/badarea_io.c @@ -34,7 +34,7 @@ int main(int argc, char **argv) { - int rc; + ssize_t rc; int fd; void *volatile buf = (void *)0x4096000; void *volatile fd_ptr; @@ -64,9 +64,9 @@ int main(int argc, char **argv) if (rc != 2UL*1024*1024) perror("write 2M"); - rc = write(fd, fd_ptr, 2UL*1024*1024*1024); - if (rc != 2UL*1024*1024*1024) - perror("write 2G"); + rc = write(fd, fd_ptr, 1UL*(1024+512)*1024*1024); + if (rc != 1UL*(1024+512)*1024*1024) + perror("write 1.5G"); rc = write(fd, fd_ptr, -2); if (rc != -2) -- 1.8.3.1