From e23f91ed79ac538fa6df6759bf4eee8fcdad41b8 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Tue, 2 Apr 2024 15:45:49 -0700 Subject: [PATCH] LU-17592 build: kernel 6.8 removed strlcpy() Linux commit v6.7-11707-gd26270061ae6 string: Remove strlcpy() strlcpy() is removed, use strscpy() and provide a strscpy() for kernels that do not have one. Lustre-change: https://review.whamcloud.com/54227 Lustre-commit: TBD (from 1861e4ce8ec6d66d17ed73042f39bacb6496685c) HPE-bug-id: LUS-12181 Signed-off-by: Shaun Tancheff Change-Id: Ieab872f20e08d17a4842bc944fa38f9867de81f9 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/54576 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Andreas Dilger --- contrib/scripts/spelling.txt | 3 +- libcfs/autoconf/lustre-libcfs.m4 | 4 +- libcfs/include/libcfs/linux/linux-misc.h | 7 ++- libcfs/libcfs/hash.c | 2 +- libcfs/libcfs/tracefile.c | 5 +- libcfs/libcfs/workitem.c | 2 +- lnet/klnds/o2iblnd/o2iblnd.c | 20 +++---- lnet/klnds/socklnd/socklnd.c | 2 +- lnet/lnet/config.c | 2 +- lnet/selftest/conrpc.c | 38 ++++++------- lnet/selftest/console.c | 98 ++++++++++++++++---------------- lnet/selftest/framework.c | 16 +++--- lustre/fid/fid_store.c | 2 +- lustre/fld/fld_cache.c | 2 +- lustre/llite/pcc.c | 2 +- lustre/lmv/lmv_obd.c | 6 +- lustre/lod/lod_internal.h | 4 +- lustre/lod/lod_lov.c | 6 +- lustre/lod/lod_object.c | 2 +- lustre/lod/lod_pool.c | 2 +- lustre/lov/lov_ea.c | 6 +- lustre/lov/lov_pack.c | 4 +- lustre/lov/lov_pool.c | 2 +- lustre/mdc/mdc_lib.c | 2 +- lustre/mdd/mdd_device.c | 2 +- lustre/mdd/mdd_dir.c | 6 +- lustre/mdt/mdt_coordinator.c | 2 +- lustre/mdt/mdt_lib.c | 2 +- lustre/mgc/mgc_request.c | 6 +- lustre/mgs/mgs_handler.c | 2 +- lustre/mgs/mgs_llog.c | 85 +++++++++++++-------------- lustre/obdclass/dt_object.c | 2 +- lustre/obdclass/jobid.c | 8 +-- lustre/obdclass/obd_config.c | 2 +- lustre/obdclass/obd_mount.c | 5 +- lustre/obdclass/obd_mount_server.c | 18 +++--- lustre/obdclass/upcall_cache.c | 4 +- lustre/ofd/ofd_access_log.c | 2 +- lustre/ofd/ofd_io.c | 2 +- lustre/ofd/ofd_objects.c | 2 +- lustre/osd-ldiskfs/osd_handler.c | 14 ++--- lustre/osd-ldiskfs/osd_lproc.c | 2 +- lustre/osd-zfs/osd_handler.c | 12 ++-- lustre/osd-zfs/osd_lproc.c | 2 +- lustre/osd-zfs/osd_oi.c | 6 +- lustre/osd-zfs/osd_quota.c | 2 +- lustre/ptlrpc/gss/gss_pipefs.c | 2 +- lustre/ptlrpc/nodemap_handler.c | 7 +-- lustre/ptlrpc/nodemap_storage.c | 2 +- lustre/ptlrpc/nrs.c | 19 ++++--- lustre/ptlrpc/nrs_tbf.c | 8 +-- lustre/ptlrpc/sec_config.c | 10 ++-- lustre/quota/qmt_dev.c | 6 +- lustre/quota/qsd_lib.c | 6 +- lustre/target/tgt_grant.c | 2 +- lustre/target/tgt_lastrcvd.c | 4 +- 56 files changed, 249 insertions(+), 244 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 46f7463..8457a44 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -189,7 +189,7 @@ mti_spec||mdi_spec mti_tattr||mdi_tattr mti_tpattr||mdi_tpattr mti_xattr_buf||mdi_xattr_buf -nla_strlcpy|nla_strscpy +nla_strlcpy||nla_strscpy OS_STATE_DEGRADED||OS_STATFS_DEGRADED OS_STATE_READONLY||OS_STATFS_READONLY OS_STATE_NOPRECREATE||OS_STATFS_NOCREATE @@ -212,6 +212,7 @@ setup_timer||cfs_timer_setup sprintf||snprintf strcat||strncat strcpy||strncpy +strlcpy||strscpy struct timeval||struct timespec64 tempnam||mkstemp time_t||timeout_t diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index fbf2b5e..cab9f17 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -541,7 +541,9 @@ AC_DEFUN([LIBCFS_SRC_STRSCPY_EXISTS], [ LB2_LINUX_TEST_SRC([strscpy_exists], [ #include ],[ - strscpy((char *)NULL, (const char *)NULL, 0); + char buf[129]; + + strscpy(buf, "something", sizeof(buf)); ],[-Werror]) ]) AC_DEFUN([LIBCFS_STRSCPY_EXISTS], [ diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index d318cce..e1c97fc 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -194,7 +194,12 @@ static inline void *cfs_kallsyms_lookup_name(const char *name) #endif #ifndef HAVE_STRSCPY -#define strscpy(s1, s2, sz) strlcpy((s1), (s2), (sz)) +static inline ssize_t strscpy(char *s1, const char *s2, size_t sz) +{ + ssize_t len = strlcpy(s1, s2, sz); + + return (len >= sz) ? -E2BIG : len; +} #endif #ifndef HAVE_KOBJ_TYPE_DEFAULT_GROUPS diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index df7ea82..291fd98 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -1069,7 +1069,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, if (hs == NULL) RETURN(NULL); - strlcpy(hs->hs_name, name, len); + strscpy(hs->hs_name, name, len); hs->hs_flags = flags; atomic_set(&hs->hs_refcount, 1); diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 73d4693..0f8454d 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -477,12 +477,13 @@ int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, debug_buf += sizeof(header); } - strlcpy(debug_buf, file, PAGE_SIZE - tage->used); + snprintf(debug_buf, PAGE_SIZE - tage->used, "%s", file); tage->used += strlen(file) + 1; debug_buf += strlen(file) + 1; if (msgdata->msg_fn) { - strlcpy(debug_buf, msgdata->msg_fn, PAGE_SIZE - tage->used); + snprintf(debug_buf, PAGE_SIZE - tage->used, "%s", + msgdata->msg_fn); tage->used += strlen(msgdata->msg_fn) + 1; debug_buf += strlen(msgdata->msg_fn) + 1; } diff --git a/libcfs/libcfs/workitem.c b/libcfs/libcfs/workitem.c index aa243a0..0a8bce8 100644 --- a/libcfs/libcfs/workitem.c +++ b/libcfs/libcfs/workitem.c @@ -348,7 +348,7 @@ cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab, LIBCFS_FREE(sched, sizeof(*sched)); return -E2BIG; } - strlcpy(sched->ws_name, name, sizeof(sched->ws_name)); + strscpy(sched->ws_name, name, sizeof(sched->ws_name)); sched->ws_cptab = cptab; sched->ws_cpt = cpt; diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index fb5a275..6d8afd8 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -2092,15 +2092,15 @@ kiblnd_init_poolset(struct kib_poolset *ps, int cpt, memset(ps, 0, sizeof(struct kib_poolset)); ps->ps_cpt = cpt; - ps->ps_net = net; - ps->ps_pool_create = po_create; - ps->ps_pool_destroy = po_destroy; - ps->ps_node_init = nd_init; - ps->ps_node_fini = nd_fini; - ps->ps_pool_size = size; - if (strlcpy(ps->ps_name, name, sizeof(ps->ps_name)) - >= sizeof(ps->ps_name)) - return -E2BIG; + ps->ps_net = net; + ps->ps_pool_create = po_create; + ps->ps_pool_destroy = po_destroy; + ps->ps_node_init = nd_init; + ps->ps_node_fini = nd_fini; + ps->ps_pool_size = size; + rc = strscpy(ps->ps_name, name, sizeof(ps->ps_name)); + if (rc < 0) + return rc; spin_lock_init(&ps->ps_lock); INIT_LIST_HEAD(&ps->ps_pool_list); INIT_LIST_HEAD(&ps->ps_failed_pool_list); @@ -3568,7 +3568,7 @@ kiblnd_startup(struct lnet_ni *ni) } ibdev->ibd_ifip = ifaces[i].li_ipaddr; - strlcpy(ibdev->ibd_ifname, ifaces[i].li_name, + strscpy(ibdev->ibd_ifname, ifaces[i].li_name, sizeof(ibdev->ibd_ifname)); ibdev->ibd_can_failover = !!(ifaces[i].li_flags & IFF_MASTER); diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index df79d6ad..149ba3a 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -2446,7 +2446,7 @@ ksocknal_startup(struct lnet_ni *ni) if (ksi->ksni_index < 0 || dev_status <= 0) lnet_set_link_fatal_state(ni, 1); ksi->ksni_netmask = ifaces[i].li_netmask; - strlcpy(ksi->ksni_name, ifaces[i].li_name, sizeof(ksi->ksni_name)); + strscpy(ksi->ksni_name, ifaces[i].li_name, sizeof(ksi->ksni_name)); /* call it before add it to ksocknal_data.ksnd_nets */ rc = ksocknal_net_start_threads(net, ni->ni_cpts, ni->ni_ncpts); diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index a19fa98..e107527 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -1600,7 +1600,7 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns) ifaces[nip].li_flags = flags; ifaces[nip].li_ipaddr = ntohl(ifa->ifa_local); ifaces[nip].li_netmask = ntohl(ifa->ifa_mask); - strlcpy(ifaces[nip].li_name, ifa->ifa_label, + strscpy(ifaces[nip].li_name, ifa->ifa_label, sizeof(ifaces[nip].li_name)); nip++; } diff --git a/lnet/selftest/conrpc.c b/lnet/selftest/conrpc.c index a3ffa45..1e31d46 100644 --- a/lnet/selftest/conrpc.c +++ b/lnet/selftest/conrpc.c @@ -593,35 +593,35 @@ lstcon_sesrpc_prep(struct lstcon_node *nd, int transop, struct srpc_rmsn_reqst *rsrq; int rc; - switch (transop) { - case LST_TRANS_SESNEW: + switch (transop) { + case LST_TRANS_SESNEW: rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, feats, 0, 0, crpc); - if (rc != 0) - return rc; + if (rc != 0) + return rc; - msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst; - msrq->mksn_sid = console_session.ses_id; - msrq->mksn_force = console_session.ses_force; - strlcpy(msrq->mksn_name, console_session.ses_name, + msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst; + msrq->mksn_sid = console_session.ses_id; + msrq->mksn_force = console_session.ses_force; + strscpy(msrq->mksn_name, console_session.ses_name, sizeof(msrq->mksn_name)); - break; + break; - case LST_TRANS_SESEND: + case LST_TRANS_SESEND: rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, feats, 0, 0, crpc); - if (rc != 0) - return rc; + if (rc != 0) + return rc; - rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst; - rsrq->rmsn_sid = console_session.ses_id; - break; + rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst; + rsrq->rmsn_sid = console_session.ses_id; + break; - default: - LBUG(); - } + default: + LBUG(); + } - return 0; + return 0; } int diff --git a/lnet/selftest/console.c b/lnet/selftest/console.c index 266c24e..c203d05 100644 --- a/lnet/selftest/console.c +++ b/lnet/selftest/console.c @@ -1746,22 +1746,22 @@ lstcon_session_new(char *name, int key, unsigned feats, if (strlen(name) > sizeof(console_session.ses_name)-1) return -E2BIG; - strlcpy(console_session.ses_name, name, + strscpy(console_session.ses_name, name, sizeof(console_session.ses_name)); - rc = lstcon_batch_add(LST_DEFAULT_BATCH); - if (rc != 0) - return rc; + rc = lstcon_batch_add(LST_DEFAULT_BATCH); + if (rc != 0) + return rc; - rc = lstcon_rpc_pinger_start(); - if (rc != 0) { + rc = lstcon_rpc_pinger_start(); + if (rc != 0) { struct lstcon_batch *bat = NULL; - lstcon_batch_find(LST_DEFAULT_BATCH, &bat); - lstcon_batch_destroy(bat); + lstcon_batch_find(LST_DEFAULT_BATCH, &bat); + lstcon_batch_destroy(bat); - return rc; - } + return rc; + } if (copy_to_user(sid_up, &console_session.ses_id, sizeof(struct lst_sid)) == 0) @@ -1912,77 +1912,77 @@ lstcon_acceptor_handle(struct srpc_server_rpc *rpc) struct lstcon_ndlink *ndl; int rc = 0; - sfw_unpack_message(req); + sfw_unpack_message(req); mutex_lock(&console_session.ses_mutex); jrep->join_sid = console_session.ses_id; if (console_session.ses_id.ses_nid == LNET_NID_ANY) { - jrep->join_status = ESRCH; - goto out; - } + jrep->join_status = ESRCH; + goto out; + } if (lstcon_session_feats_check(req->msg_ses_feats) != 0) { jrep->join_status = EPROTO; goto out; } - if (jreq->join_sid.ses_nid != LNET_NID_ANY && - !lstcon_session_match(jreq->join_sid)) { - jrep->join_status = EBUSY; - goto out; - } + if (jreq->join_sid.ses_nid != LNET_NID_ANY && + !lstcon_session_match(jreq->join_sid)) { + jrep->join_status = EBUSY; + goto out; + } - if (lstcon_group_find(jreq->join_group, &grp) != 0) { - rc = lstcon_group_alloc(jreq->join_group, &grp); - if (rc != 0) { - CERROR("Out of memory\n"); - goto out; - } + if (lstcon_group_find(jreq->join_group, &grp) != 0) { + rc = lstcon_group_alloc(jreq->join_group, &grp); + if (rc != 0) { + CERROR("Out of memory\n"); + goto out; + } list_add_tail(&grp->grp_link, &console_session.ses_grp_list); lstcon_group_addref(grp); } - if (grp->grp_ref > 2) { - /* Group in using */ - jrep->join_status = EBUSY; - goto out; - } + if (grp->grp_ref > 2) { + /* Group in using */ + jrep->join_status = EBUSY; + goto out; + } - rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0); - if (rc == 0) { - jrep->join_status = EEXIST; - goto out; - } + rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0); + if (rc == 0) { + jrep->join_status = EEXIST; + goto out; + } - rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1); - if (rc != 0) { - CERROR("Out of memory\n"); - goto out; - } + rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1); + if (rc != 0) { + CERROR("Out of memory\n"); + goto out; + } - ndl->ndl_node->nd_state = LST_NODE_ACTIVE; - ndl->ndl_node->nd_timeout = console_session.ses_timeout; + ndl->ndl_node->nd_state = LST_NODE_ACTIVE; + ndl->ndl_node->nd_timeout = console_session.ses_timeout; - if (grp->grp_userland == 0) - grp->grp_userland = 1; + if (grp->grp_userland == 0) + grp->grp_userland = 1; - strlcpy(jrep->join_session, console_session.ses_name, + strscpy(jrep->join_session, console_session.ses_name, sizeof(jrep->join_session)); - jrep->join_timeout = console_session.ses_timeout; - jrep->join_status = 0; + jrep->join_timeout = console_session.ses_timeout; + jrep->join_status = 0; out: rep->msg_ses_feats = console_session.ses_features; - if (grp != NULL) + if (grp != NULL) lstcon_group_decref(grp); mutex_unlock(&console_session.ses_mutex); - return rc; + return rc; } static struct srpc_service lstcon_acceptor_service; diff --git a/lnet/selftest/framework.c b/lnet/selftest/framework.c index cced64d..bc305b9 100644 --- a/lnet/selftest/framework.c +++ b/lnet/selftest/framework.c @@ -274,7 +274,7 @@ sfw_init_session(struct sfw_session *sn, struct lst_sid sid, atomic_set(&sn->sn_refcount, 1); /* +1 for caller */ atomic_set(&sn->sn_brw_errors, 0); atomic_set(&sn->sn_ping_errors, 0); - strlcpy(&sn->sn_name[0], name, sizeof(sn->sn_name)); + strscpy(&sn->sn_name[0], name, sizeof(sn->sn_name)); sn->sn_timer_active = 0; sn->sn_id = sid; @@ -434,10 +434,10 @@ sfw_make_session(struct srpc_mksn_reqst *request, struct srpc_mksn_reply *reply) if (!request->mksn_force) { reply->mksn_status = EBUSY; - cplen = strlcpy(&reply->mksn_name[0], &sn->sn_name[0], + cplen = strscpy(&reply->mksn_name[0], &sn->sn_name[0], sizeof(reply->mksn_name)); - if (cplen >= sizeof(reply->mksn_name)) - return -E2BIG; + if (cplen < 0) + return cplen; return 0; } } @@ -515,6 +515,7 @@ sfw_debug_session(struct srpc_debug_reqst *request, struct srpc_debug_reply *reply) { struct sfw_session *sn = sfw_data.fw_session; + int cplen; if (sn == NULL) { reply->dbg_status = ESRCH; @@ -525,9 +526,10 @@ sfw_debug_session(struct srpc_debug_reqst *request, reply->dbg_status = 0; reply->dbg_sid = sn->sn_id; reply->dbg_timeout = sn->sn_timeout; - if (strlcpy(reply->dbg_name, &sn->sn_name[0], sizeof(reply->dbg_name)) - >= sizeof(reply->dbg_name)) - return -E2BIG; + cplen = strscpy(reply->dbg_name, &sn->sn_name[0], + sizeof(reply->dbg_name)); + if (cplen < 0) + return cplen; return 0; } diff --git a/lustre/fid/fid_store.c b/lustre/fid/fid_store.c index f0f15d8..1bdfd3e 100644 --- a/lustre/fid/fid_store.c +++ b/lustre/fid/fid_store.c @@ -89,7 +89,7 @@ static int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq) dcb = &ccb->suc_cb; dcb->dcb_func = seq_update_cb; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) diff --git a/lustre/fld/fld_cache.c b/lustre/fld/fld_cache.c index 9f322f4..8a8ad4f 100644 --- a/lustre/fld/fld_cache.c +++ b/lustre/fld/fld_cache.c @@ -69,7 +69,7 @@ struct fld_cache *fld_cache_init(const char *name, int cache_size, cache->fci_cache_count = 0; rwlock_init(&cache->fci_lock); - strlcpy(cache->fci_name, name, sizeof(cache->fci_name)); + strscpy(cache->fci_name, name, sizeof(cache->fci_name)); cache->fci_cache_size = cache_size; cache->fci_threshold = cache_threshold; diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 6c51c673..4e63def 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -4679,7 +4679,7 @@ int pcc_ioctl_state(struct file *file, struct inode *inode, pcc_inode_detach_put(inode); } - if (strlcpy(state->pccs_path, path, buf_len) >= buf_len) + if (strscpy(state->pccs_path, path, buf_len) < 0) GOTO(out_unlock, rc = -ENAMETOOLONG); out_unlock: diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index a0c248c..fa74db9 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -3591,11 +3591,11 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm, lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version); lsm->lsm_md_migrate_offset = le32_to_cpu(lmm1->lmv_migrate_offset); lsm->lsm_md_migrate_hash = le32_to_cpu(lmm1->lmv_migrate_hash); - cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name, + cplen = strscpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name, sizeof(lsm->lsm_md_pool_name)); - if (cplen >= sizeof(lsm->lsm_md_pool_name)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); CDEBUG(D_INFO, "unpack lsm count %d/%d, master %d hash_type %#x/%#x " "layout_version %d\n", lsm->lsm_md_stripe_count, diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 662f3d2..bebb0d3 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -368,7 +368,7 @@ static inline int lod_set_pool(char **pool, const char *new_pool) OBD_ALLOC(*pool, len); if (*pool == NULL) return -ENOMEM; - strlcpy(*pool, new_pool, len); + strscpy(*pool, new_pool, len); } return 0; } @@ -642,7 +642,7 @@ static inline void lod_layout_get_pool(struct lod_layout_component *entries, if (entries[i].llc_magic == LOV_MAGIC_FOREIGN) continue; if (entries[i].llc_pool != NULL) { - strlcpy(pool, entries[i].llc_pool, len); + strscpy(pool, entries[i].llc_pool, len); break; } } diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index e9adc4d..df16ab2 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -790,11 +790,11 @@ static int lod_gen_component_ea(const struct lu_env *env, objs = &lmm->lmm_objects[0]; } else { struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *)lmm; - size_t cplen = strlcpy(v3->lmm_pool_name, + size_t cplen = strscpy(v3->lmm_pool_name, lod_comp->llc_pool, sizeof(v3->lmm_pool_name)); - if (cplen >= sizeof(v3->lmm_pool_name)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); objs = &v3->lmm_objects[0]; } stripe_count = lod_comp_entry_stripe_count(lo, comp_idx, is_dir); diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 34e8ce7..8e58339 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -4781,7 +4781,7 @@ static int lod_xattr_set(const struct lu_env *env, cpu_to_le32(v1->lmm_stripe_offset); v3->lmm_stripe_size = cpu_to_le32(v1->lmm_stripe_size); - strlcpy(v3->lmm_pool_name, pool, + strscpy(v3->lmm_pool_name, pool, sizeof(v3->lmm_pool_name)); info->lti_buf.lb_buf = v3; diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index fe99956..4a90d3e 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -431,7 +431,7 @@ int lod_pool_new(struct obd_device *obd, char *poolname) if (new_pool == NULL) RETURN(-ENOMEM); - strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); + strscpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); new_pool->pool_spill_target[0] = '\0'; atomic_set(&new_pool->pool_spill_hit, 0); new_pool->pool_lobd = obd; diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c index c864221..14b0852 100644 --- a/lustre/lov/lov_ea.c +++ b/lustre/lov/lov_ea.c @@ -251,10 +251,10 @@ lsme_unpack(struct lov_obd *lov, struct lov_mds_md *lmm, size_t buf_size, if (pool_name) { size_t pool_name_len; - pool_name_len = strlcpy(lsme->lsme_pool_name, pool_name, + pool_name_len = strscpy(lsme->lsme_pool_name, pool_name, sizeof(lsme->lsme_pool_name)); - if (pool_name_len >= sizeof(lsme->lsme_pool_name)) - GOTO(out_lsme, rc = -E2BIG); + if (pool_name_len < 0) + GOTO(out_lsme, rc = pool_name_len); } /* with Data-on-MDT set maxbytes to stripe size */ diff --git a/lustre/lov/lov_pack.c b/lustre/lov/lov_pack.c index 16ea44f..1ccf700 100644 --- a/lustre/lov/lov_pack.c +++ b/lustre/lov/lov_pack.c @@ -133,7 +133,7 @@ static ssize_t lov_lsm_pack_v1v3(const struct lov_stripe_md *lsm, void *buf, if (lsm->lsm_magic == LOV_MAGIC_V3) { BUILD_BUG_ON(sizeof(lsm->lsm_entries[0]->lsme_pool_name) != sizeof(lmmv3->lmm_pool_name)); - strlcpy(lmmv3->lmm_pool_name, + strscpy(lmmv3->lmm_pool_name, lsm->lsm_entries[0]->lsme_pool_name, sizeof(lmmv3->lmm_pool_name)); lmm_objects = lmmv3->lmm_objects; @@ -210,7 +210,7 @@ unsigned int lov_lsme_pack_v1v3(struct lov_stripe_md_entry *lsme, if (lsme->lsme_magic == LOV_MAGIC_V3) { struct lov_mds_md_v3 *lmmv3 = (struct lov_mds_md_v3 *)lmm; - strlcpy(lmmv3->lmm_pool_name, lsme->lsme_pool_name, + strscpy(lmmv3->lmm_pool_name, lsme->lsme_pool_name, sizeof(lmmv3->lmm_pool_name)); lmm_objects = lmmv3->lmm_objects; } else { diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index ff015db..9f2fc5c 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -398,7 +398,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname) if (new_pool == NULL) RETURN(-ENOMEM); - strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); + strscpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); new_pool->pool_lobd = obd; /* ref count init to 1 because when created a pool is always used * up to deletion diff --git a/lustre/mdc/mdc_lib.c b/lustre/mdc/mdc_lib.c index 2748e1b..62b9bd0 100644 --- a/lustre/mdc/mdc_lib.c +++ b/lustre/mdc/mdc_lib.c @@ -114,7 +114,7 @@ static void mdc_pack_name(struct req_capsule *pill, buf[name_len] = '\0'; return; } - cpy_len = strlcpy(buf, name, buf_size); + cpy_len = strscpy(buf, name, buf_size); LASSERT(lu_name_is_valid_2(buf, cpy_len)); if (cpy_len != name_len) diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 96399ae..913ca82 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -1802,7 +1802,7 @@ static int mdd_changelog_user_register(const struct lu_env *env, rc = mdd_changelog_name_check(env, ctxt, mdd, name); if (rc) GOTO(out_users, rc); - strlcpy(rec->cur_name, name, sizeof(rec->cur_name)); + strscpy(rec->cur_name, name, sizeof(rec->cur_name)); } mdd_chlg_username(rec, user_name, sizeof(user_name)); diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index dab561c..6aa9d28 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -1036,7 +1036,7 @@ static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec, rnm->cr_spfid = *spfid; changelog_rec_name(rec)[rec->cr_namelen] = '\0'; - strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize); + strscpy(changelog_rec_sname(rec), sname->ln_name, extsize); rec->cr_namelen += extsize; } @@ -1047,7 +1047,7 @@ void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid) if (jobid == NULL || jobid[0] == '\0') return; - strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid)); + strscpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid)); } void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags) @@ -1086,7 +1086,7 @@ void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec, { struct changelog_ext_xattr *xattr = changelog_rec_xattr(rec); - strlcpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr)); + strscpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr)); } /** diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index fb7608d..159ada9 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -256,7 +256,7 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env, RETURN(-ENOMEM); hal->hal_version = HAL_VERSION; - strlcpy(hal->hal_fsname, hsd->hsd_fsname, MTI_NAME_MAXLEN + 1); + strscpy(hal->hal_fsname, hsd->hsd_fsname, MTI_NAME_MAXLEN + 1); hal->hal_archive_id = larr->arr_archive_id; hal->hal_flags = larr->arr_flags; hal->hal_count = 0; diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index 2ad11c8..6d501e9 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -135,7 +135,7 @@ static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc) /* set jobid if specified. */ if (jobid) - strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid)); + strscpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid)); else uc->uc_jobid[0] = '\0'; } diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index dbe6cfb..c190486 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -1692,9 +1692,9 @@ again: body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY); LASSERT(body != NULL); LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname)); - if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)) - >= sizeof(body->mcb_name)) - GOTO(out, rc = -E2BIG); + rc = strscpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)); + if (rc < 0) + GOTO(out, rc); if (cld_is_nodemap(cld)) body->mcb_offset = config_read_offset; else diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 7e64ca3..fe94664 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -720,7 +720,7 @@ static int mgs_extract_fs_pool(char *arg, char *fsname, char *poolname) /* Also make sure poolname is not to long. */ if (strlen(ptr) > LOV_MAXPOOLNAME) return -ENAMETOOLONG; - strlcpy(poolname, ptr, LOV_MAXPOOLNAME + 1); + strscpy(poolname, ptr, LOV_MAXPOOLNAME + 1); /* Test if fsname is empty */ len = strlen(arg) - strlen(ptr) - 1; diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index f129f55..190f5b3 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -832,14 +832,14 @@ static int mgs_check_marker(const struct lu_env *env, struct mgs_device *mgs, OBD_ALLOC_PTR(mc_marker); if (!mc_marker) GOTO(out_close, rc = -ENOMEM); - if (strlcpy(mc_marker->cm_comment, comment, - sizeof(mc_marker->cm_comment)) >= - sizeof(mc_marker->cm_comment)) - GOTO(out_free, rc = -E2BIG); - if (strlcpy(mc_marker->cm_tgtname, devname, - sizeof(mc_marker->cm_tgtname)) >= - sizeof(mc_marker->cm_tgtname)) - GOTO(out_free, rc = -E2BIG); + rc = strscpy(mc_marker->cm_comment, comment, + sizeof(mc_marker->cm_comment)); + if (rc < 0) + GOTO(out_free, rc); + rc = strscpy(mc_marker->cm_tgtname, devname, + sizeof(mc_marker->cm_tgtname)); + if (rc < 0) + GOTO(out_free, rc); rc = llog_process(env, loghandle, mgs_check_record_match, (void *)mc_marker, NULL); @@ -945,14 +945,14 @@ static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs, OBD_ALLOC_PTR(mml); if (!mml) GOTO(out_close, rc = -ENOMEM); - if (strlcpy(mml->mml_marker.cm_comment, comment, - sizeof(mml->mml_marker.cm_comment)) >= - sizeof(mml->mml_marker.cm_comment)) - GOTO(out_free, rc = -E2BIG); - if (strlcpy(mml->mml_marker.cm_tgtname, devname, - sizeof(mml->mml_marker.cm_tgtname)) >= - sizeof(mml->mml_marker.cm_tgtname)) - GOTO(out_free, rc = -E2BIG); + rc = strscpy(mml->mml_marker.cm_comment, comment, + sizeof(mml->mml_marker.cm_comment)); + if (rc < 0) + GOTO(out_free, rc); + rc = strscpy(mml->mml_marker.cm_tgtname, devname, + sizeof(mml->mml_marker.cm_tgtname)); + if (rc < 0) + GOTO(out_free, rc); /* Modify mostly means cancel */ mml->mml_marker.cm_flags = flags; mml->mml_marker.cm_canceltime = flags ? ktime_get_real_seconds() : 0; @@ -1399,11 +1399,11 @@ static int mgs_replace_log(const struct lu_env *env, GOTO(out_close, rc = -ENOMEM); /* devname is only needed information to replace UUID records */ if (devname) - strlcpy(mrd->target.mti_svname, devname, + strscpy(mrd->target.mti_svname, devname, sizeof(mrd->target.mti_svname)); /* data is parsed in llog callback */ if (data) - strlcpy(mrd->target.mti_params, data, + strscpy(mrd->target.mti_params, data, sizeof(mrd->target.mti_params)); /* Copy records to this temporary llog */ mrd->temp_llh = orig_llh; @@ -1892,14 +1892,14 @@ static int record_marker(const struct lu_env *env, mgi->mgi_marker.cm_step = fsdb->fsdb_gen; mgi->mgi_marker.cm_flags = flags; mgi->mgi_marker.cm_vers = LUSTRE_VERSION_CODE; - cplen = strlcpy(mgi->mgi_marker.cm_tgtname, tgtname, + cplen = strscpy(mgi->mgi_marker.cm_tgtname, tgtname, sizeof(mgi->mgi_marker.cm_tgtname)); - if (cplen >= sizeof(mgi->mgi_marker.cm_tgtname)) - return -E2BIG; - cplen = strlcpy(mgi->mgi_marker.cm_comment, comment, + if (cplen < 0) + return cplen; + cplen = strscpy(mgi->mgi_marker.cm_comment, comment, sizeof(mgi->mgi_marker.cm_comment)); - if (cplen >= sizeof(mgi->mgi_marker.cm_comment)) - return -E2BIG; + if (cplen < 0) + return cplen; mgi->mgi_marker.cm_createtime = ktime_get_real_seconds(); mgi->mgi_marker.cm_canceltime = 0; lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL); @@ -2132,10 +2132,10 @@ static int mgs_steal_client_llog_handler(const struct lu_env *env, (marker->cm_flags & CM_START) && !(marker->cm_flags & CM_SKIP)) { got_an_osc_or_mdc = 1; - cplen = strlcpy(tmti->mti_svname, marker->cm_tgtname, + cplen = strscpy(tmti->mti_svname, marker->cm_tgtname, sizeof(tmti->mti_svname)); - if (cplen >= sizeof(tmti->mti_svname)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); rc = record_start_log(env, mgs, &mdt_llh, mti->mti_svname); if (rc) @@ -3330,7 +3330,7 @@ static int mgs_wlp_lcfg(const struct lu_env *env, int rc, del; /* Erase any old settings of this same parameter */ - strlcpy(comment, ptr, sizeof(comment)); + strscpy(comment, ptr, sizeof(comment)); /* But don't try to match the value. */ tmp = strchr(comment, '='); if (tmp != NULL) @@ -3909,11 +3909,9 @@ static int mgs_write_log_param2(const struct lu_env *env, } param = strstr(ptr, PARAM_FAILNODE); - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) { - rc = -E2BIG; + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) goto end; - } CDEBUG(D_MGS, "Adding failnode with param %s\n", mti->mti_params); @@ -5222,9 +5220,9 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, "%.*s", (int)len, param); param += len + 1; } else { - if (strlcpy(mti->mti_svname, devname, sizeof(mti->mti_svname)) >= - sizeof(mti->mti_svname)) - RETURN(-E2BIG); + rc = strscpy(mti->mti_svname, devname, sizeof(mti->mti_svname)); + if (rc < 0) + RETURN(rc); } if (!strlen(mti->mti_svname)) { @@ -5238,7 +5236,7 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, /* For this case we have an invalid obd device name */ case -ENXIO: CDEBUG(D_MGS, "%s don't contain an index\n", mti->mti_svname); - strlcpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); + strscpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); dev_type = 0; break; /* Not an obd device, assume devname is the fsname. @@ -5246,7 +5244,7 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, */ case -EINVAL: CDEBUG(D_MGS, "%s is seen as a file system name\n", mti->mti_svname); - strlcpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); + strscpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); dev_type = 0; break; default: @@ -5271,10 +5269,9 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, } break; } - - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) - GOTO(out, rc = -E2BIG); + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) + GOTO(out, rc); CDEBUG(D_MGS, "set_conf_param fs='%s' device='%s' param='%s'\n", mti->mti_fsname, mti->mti_svname, mti->mti_params); @@ -5318,9 +5315,9 @@ static int mgs_set_param2(const struct lu_env *env, struct mgs_device *mgs, size_t len; int rc; - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) - GOTO(out, rc = -E2BIG); + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) + GOTO(out, rc); len = strcspn(param, ".="); if (len && param[len] != '=') { diff --git a/lustre/obdclass/dt_object.c b/lustre/obdclass/dt_object.c index cec9952..f063018 100644 --- a/lustre/obdclass/dt_object.c +++ b/lustre/obdclass/dt_object.c @@ -344,7 +344,7 @@ dt_store_resolve(const struct lu_env *env, struct dt_device *dt, dfh->dfh_dt = dt; dfh->dfh_fid = fid; - strlcpy(info->dti_buf, path, sizeof(info->dti_buf)); + strscpy(info->dti_buf, path, sizeof(info->dti_buf)); result = dt->dd_ops->dt_root_get(env, dt, fid); if (result == 0) { diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 939d5c2..8e9a7a3 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -523,7 +523,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) rcu_read_lock(); jid = jobid_current(); if (jid) { - strlcpy(jobid, jid, joblen); + strscpy(jobid, jid, joblen); joblen = strlen(jobid); } else { rc = -ENOENT; @@ -602,7 +602,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) spin_lock(&pidmap->jp_lock); if (!rc) { pidmap->jp_joblen = env_len; - strlcpy(pidmap->jp_jobid, env_jobid, + strscpy(pidmap->jp_jobid, env_jobid, sizeof(pidmap->jp_jobid)); rc = 0; } else if (rc == -ENOENT) { @@ -619,7 +619,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) * If a cached missing entry was found, return -ENOENT. */ if (pidmap->jp_joblen) { - strlcpy(jobid, pidmap->jp_jobid, joblen); + strscpy(jobid, pidmap->jp_jobid, joblen); joblen = pidmap->jp_joblen; rc = 0; } else if (!rc) { @@ -955,7 +955,7 @@ void lustre_jobid_clear(const char *find_jobid) if (jobid_hash == NULL) return; - strlcpy(jobid, find_jobid, sizeof(jobid)); + strscpy(jobid, find_jobid, sizeof(jobid)); /* trim \n off the end of the incoming jobid */ end = strchr(jobid, '\n'); if (end && *end == '\n') diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index ec3d385..2fb0c2b 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1233,7 +1233,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg, if (!new_param) GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM)); - strlcpy(new_param, new_name, new_len); + strscpy(new_param, new_name, new_len); if (value) strcat(new_param, value); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index d0c6316..51307c3 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -830,8 +830,9 @@ int server_name2svname(const char *label, char *svname, const char **endptr, if (endptr != NULL) *endptr = dash; - if (strlcpy(svname, dash + 1, svsize) >= svsize) - return -E2BIG; + rc = strscpy(svname, dash + 1, svsize); + if (rc < 0) + return rc; return 0; } diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index 886cac0..64bb7ae 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -1156,9 +1156,9 @@ static int server_lsi2mti(struct lustre_sb_info *lsi, if (!IS_SERVER(lsi)) RETURN(-EINVAL); - if (strlcpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname)) - >= sizeof(mti->mti_svname)) - RETURN(-E2BIG); + rc = strscpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname)); + if (rc < 0) + return rc; mti->mti_nid_count = 0; while (LNetGetId(i++, &id) != -ENOENT) { @@ -1209,10 +1209,10 @@ static int server_lsi2mti(struct lustre_sb_info *lsi, mti->mti_flags = lsi->lsi_flags & LDD_F_MASK; if (mti->mti_flags & (LDD_F_WRITECONF | LDD_F_VIRGIN)) mti->mti_flags |= LDD_F_UPDATE; - cplen = strlcpy(mti->mti_params, lsi->lsi_lmd->lmd_params, + cplen = strscpy(mti->mti_params, lsi->lsi_lmd->lmd_params, sizeof(mti->mti_params)); - if (cplen >= sizeof(mti->mti_params)) - return -E2BIG; + if (cplen < 0) + return cplen; return 0; } @@ -1529,12 +1529,12 @@ static int lsi_prepare(struct lustre_sb_info *lsi) strlen(fstype) >= sizeof(lsi->lsi_fstype)) RETURN(-ENAMETOOLONG); - strlcpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile, + strscpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile, sizeof(lsi->lsi_svname)); - strlcpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type)); + strscpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type)); /* XXX: a temp. solution for components using ldiskfs * to be removed in one of the subsequent patches */ - strlcpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype)); + strscpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype)); /* Determine server type */ rc = server_name2index(lsi->lsi_svname, &index, NULL); diff --git a/lustre/obdclass/upcall_cache.c b/lustre/obdclass/upcall_cache.c index b52849d..e7aea75 100644 --- a/lustre/obdclass/upcall_cache.c +++ b/lustre/obdclass/upcall_cache.c @@ -514,9 +514,9 @@ struct upcall_cache *upcall_cache_init(const char *name, const char *upcall, RETURN(ERR_PTR(-ENOMEM)); for (i = 0; i < cache->uc_hashsize; i++) INIT_LIST_HEAD(&cache->uc_hashtable[i]); - strlcpy(cache->uc_name, name, sizeof(cache->uc_name)); + strscpy(cache->uc_name, name, sizeof(cache->uc_name)); /* upcall pathname proc tunable */ - strlcpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall)); + strscpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall)); cache->uc_entry_expire = entry_expire; cache->uc_acquire_expire = acquire_expire; cache->uc_acquire_replay = replayable; diff --git a/lustre/ofd/ofd_access_log.c b/lustre/ofd/ofd_access_log.c index b37c4dd..b4acc55 100644 --- a/lustre/ofd/ofd_access_log.c +++ b/lustre/ofd/ofd_access_log.c @@ -467,7 +467,7 @@ struct ofd_access_log *ofd_access_log_create(const char *ofd_name, size_t size) if (!oal) return ERR_PTR(-ENOMEM); - strlcpy(oal->oal_name, ofd_name, sizeof(oal->oal_name)); + strscpy(oal->oal_name, ofd_name, sizeof(oal->oal_name)); oal->oal_log_size = size; oal->oal_entry_size = entry_size; INIT_LIST_HEAD(&oal->oal_circ_buf_list); diff --git a/lustre/ofd/ofd_io.c b/lustre/ofd/ofd_io.c index 239d466..079259e 100644 --- a/lustre/ofd/ofd_io.c +++ b/lustre/ofd/ofd_io.c @@ -1707,7 +1707,7 @@ static int ofd_soft_sync_cb_add(struct thandle *th, struct obd_export *exp) dcb = &ossc->ossc_cb; dcb->dcb_func = ofd_cb_soft_sync; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "ofd_cb_soft_sync", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "ofd_cb_soft_sync", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index 9aa455e..b025b4c 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -221,7 +221,7 @@ static int ofd_precreate_cb_add(const struct lu_env *env, struct thandle *th, dcb = &opc->opc_cb; dcb->dcb_func = ofd_cb_precreate; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 3923b99..0f5a9f5 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -8192,10 +8192,10 @@ static int osd_device_init(const struct lu_env *env, struct lu_device *d, const char *name, struct lu_device *next) { struct osd_device *osd = osd_dev(d); + int cplen = strscpy(osd->od_svname, name, sizeof(osd->od_svname)); - if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname)) >= - sizeof(osd->od_svname)) - return -E2BIG; + if (cplen < 0) + return cplen; return osd_procfs_init(osd, name); } @@ -8567,12 +8567,10 @@ static int osd_device_init0(const struct lu_env *env, /* default fallocate to unwritten extents: LU-14326/LU-14333 */ o->od_fallocate_zero_blocks = 0; - cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4), + cplen = strscpy(o->od_svname, lustre_cfg_string(cfg, 4), sizeof(o->od_svname)); - if (cplen >= sizeof(o->od_svname)) { - rc = -E2BIG; - GOTO(out, rc); - } + if (cplen < 0) + GOTO(out, rc = cplen); o->od_index_backup_stop = 0; o->od_index = -1; /* -1 means index is invalid */ diff --git a/lustre/osd-ldiskfs/osd_lproc.c b/lustre/osd-ldiskfs/osd_lproc.c index feb8ad4..1682d3b 100644 --- a/lustre/osd-ldiskfs/osd_lproc.c +++ b/lustre/osd-ldiskfs/osd_lproc.c @@ -100,7 +100,7 @@ static void osd_symlink_brw_stats(struct osd_device *osd) if (len_root > (p - path) || len_root + len_path + 16 > PATH_MAX) goto out; - strlcpy(path, root, len_root); + strscpy(path, root, len_root); if (p > path + len_root) { s = path + len_root; while ((*s++ = *p++) != '\0'); diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 66ae9ac..a8b2d37 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -1117,13 +1117,13 @@ static int osd_mount(const struct lu_env *env, if (mntdev == NULL || svname == NULL) RETURN(-EINVAL); - rc = strlcpy(o->od_mntdev, mntdev, sizeof(o->od_mntdev)); - if (rc >= sizeof(o->od_mntdev)) - RETURN(-E2BIG); + rc = strscpy(o->od_mntdev, mntdev, sizeof(o->od_mntdev)); + if (rc < 0) + RETURN(rc); - rc = strlcpy(o->od_svname, svname, sizeof(o->od_svname)); - if (rc >= sizeof(o->od_svname)) - RETURN(-E2BIG); + rc = strscpy(o->od_svname, svname, sizeof(o->od_svname)); + if (rc < 0) + RETURN(rc); opts = lustre_cfg_string(cfg, 3); diff --git a/lustre/osd-zfs/osd_lproc.c b/lustre/osd-zfs/osd_lproc.c index 20c85fd..8856061 100644 --- a/lustre/osd-zfs/osd_lproc.c +++ b/lustre/osd-zfs/osd_lproc.c @@ -68,7 +68,7 @@ static void osd_symlink_brw_stats(struct osd_device *osd) if (len_root > (p - path) || len_root + len_path + 16 > PATH_MAX) goto out; - strlcpy(path, root, len_root); + strscpy(path, root, len_root); if (p > path + len_root) { s = path + len_root; while ((*s++ = *p++) != '\0'); diff --git a/lustre/osd-zfs/osd_oi.c b/lustre/osd-zfs/osd_oi.c index 94a8f91..268538d 100644 --- a/lustre/osd-zfs/osd_oi.c +++ b/lustre/osd-zfs/osd_oi.c @@ -131,9 +131,9 @@ osd_oi_lookup(const struct lu_env *env, struct osd_device *o, if (rc) return rc; - rc = strlcpy(oi->oi_name, name, sizeof(oi->oi_name)); - if (rc >= sizeof(oi->oi_name)) - return -E2BIG; + rc = strscpy(oi->oi_name, name, sizeof(oi->oi_name)); + if (rc < 0) + return rc; oi->oi_zapid = zde->zde_dnode; diff --git a/lustre/osd-zfs/osd_quota.c b/lustre/osd-zfs/osd_quota.c index f947b1d..8e7134a 100644 --- a/lustre/osd-zfs/osd_quota.c +++ b/lustre/osd-zfs/osd_quota.c @@ -376,7 +376,7 @@ static int osd_it_acct_rec(const struct lu_env *env, /* inode accounting is maintained by DMU since 0.7.0 */ strncpy(info->oti_buf, OSD_DMU_USEROBJ_PREFIX, OSD_DMU_USEROBJ_PREFIX_LEN); - strlcpy(info->oti_buf + OSD_DMU_USEROBJ_PREFIX_LEN, za->za_name, + strscpy(info->oti_buf + OSD_DMU_USEROBJ_PREFIX_LEN, za->za_name, sizeof(info->oti_buf) - OSD_DMU_USEROBJ_PREFIX_LEN); rc = osd_zap_lookup(osd, it->oiq_obj->oo_dn->dn_object, it->oiq_obj->oo_dn, info->oti_buf, sizeof(uint64_t), diff --git a/lustre/ptlrpc/gss/gss_pipefs.c b/lustre/ptlrpc/gss/gss_pipefs.c index 5e1e7ca..93d350d 100644 --- a/lustre/ptlrpc/gss/gss_pipefs.c +++ b/lustre/ptlrpc/gss/gss_pipefs.c @@ -1081,7 +1081,7 @@ int gss_ctx_refresh_pf(struct ptlrpc_cli_ctx *ctx) gmsg->gum_data.gum_gid = 0; /* not used for now */ gmsg->gum_data.gum_svc = import_to_gss_svc(imp); gmsg->gum_data.gum_nid = imp->imp_connection->c_peer.nid; - strlcpy(gmsg->gum_data.gum_obd, imp->imp_obd->obd_name, + strscpy(gmsg->gum_data.gum_obd, imp->imp_obd->obd_name, sizeof(gmsg->gum_data.gum_obd)); /* This only could happen when sysadmin set it dead/expired diff --git a/lustre/ptlrpc/nodemap_handler.c b/lustre/ptlrpc/nodemap_handler.c index ca8ec06..9b9f3e0 100644 --- a/lustre/ptlrpc/nodemap_handler.c +++ b/lustre/ptlrpc/nodemap_handler.c @@ -953,9 +953,8 @@ static int nodemap_set_fileset_helper(struct nodemap_config *config, nodemap->nm_fileset[0] = '\0'; else if (fileset[0] != '/') rc = -EINVAL; - else if (strlcpy(nodemap->nm_fileset, fileset, - sizeof(nodemap->nm_fileset)) >= - sizeof(nodemap->nm_fileset)) + else if (strscpy(nodemap->nm_fileset, fileset, + sizeof(nodemap->nm_fileset)) < 0) rc = -ENAMETOOLONG; return rc; @@ -1077,7 +1076,7 @@ int nodemap_set_sepol(const char *name, const char *sepol) /* truncation cannot happen, as string length was checked in * nodemap_validate_sepol() */ - strlcpy(nodemap->nm_sepol, sepol, sizeof(nodemap->nm_sepol)); + strscpy(nodemap->nm_sepol, sepol, sizeof(nodemap->nm_sepol)); out_putref: mutex_unlock(&active_config_lock); diff --git a/lustre/ptlrpc/nodemap_storage.c b/lustre/ptlrpc/nodemap_storage.c index ebfe049..caf1c31 100644 --- a/lustre/ptlrpc/nodemap_storage.c +++ b/lustre/ptlrpc/nodemap_storage.c @@ -778,7 +778,7 @@ static int nodemap_cluster_rec_helper(struct nodemap_config *config, mutex_lock(&active_config_lock); old_nm = nodemap_lookup(rec->ncr.ncr_name); if (!IS_ERR(old_nm) && old_nm->nm_fileset[0] != '\0') - strlcpy(nodemap->nm_fileset, old_nm->nm_fileset, + strscpy(nodemap->nm_fileset, old_nm->nm_fileset, sizeof(nodemap->nm_fileset)); mutex_unlock(&active_config_lock); if (!IS_ERR(old_nm)) diff --git a/lustre/ptlrpc/nrs.c b/lustre/ptlrpc/nrs.c index 52d3225..c9b368e 100644 --- a/lustre/ptlrpc/nrs.c +++ b/lustre/ptlrpc/nrs.c @@ -207,6 +207,12 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg) if (policy->pol_state == NRS_POL_STATE_STOPPING) RETURN(-EAGAIN); + if (arg && strlen(arg) >= sizeof(policy->pol_arg)) { + rc = -EINVAL; + CWARN("NRS: arg '%s' is too long: rc = %d\n", arg, rc); + return rc; + } + if (policy->pol_flags & PTLRPC_NRS_FL_FALLBACK) { /** * This is for cases in which the user sets the policy to the @@ -286,15 +292,10 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg) } } - if (arg != NULL) { - if (strlcpy(policy->pol_arg, arg, sizeof(policy->pol_arg)) >= - sizeof(policy->pol_arg)) { - CERROR("NRS: arg '%s' is too long\n", arg); - GOTO(out, rc = -E2BIG); - } - } else { + if (arg) + strscpy(policy->pol_arg, arg, sizeof(policy->pol_arg)); + else policy->pol_arg[0] = '\0'; - } policy->pol_state = NRS_POL_STATE_STARTED; @@ -1213,7 +1214,7 @@ int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf) if (desc == NULL) GOTO(fail, rc = -ENOMEM); - if (strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >= + if (strscpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >= sizeof(desc->pd_name)) { OBD_FREE_PTR(desc); GOTO(fail, rc = -E2BIG); diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 3873c53..fb5e189 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -1644,8 +1644,8 @@ static inline void nrs_tbf_cli_gen_key(struct nrs_tbf_client *cli, if (cli) { INIT_LIST_HEAD(&cli->tc_lru); - strlcpy(cli->tc_key, keystr, sizeof(cli->tc_key)); - strlcpy(cli->tc_jobid, jobid, sizeof(cli->tc_jobid)); + strscpy(cli->tc_key, keystr, sizeof(cli->tc_key)); + strscpy(cli->tc_jobid, jobid, sizeof(cli->tc_jobid)); cli->tc_nid = req->rq_peer.nid; cli->tc_opcode = opc; cli->tc_id = id; @@ -2616,7 +2616,7 @@ static int nrs_tbf_ug_id_parse(struct nrs_tbf_cmd *cmd, char *id) if (cmd->u.tc_start.ts_ids_str == NULL) return -ENOMEM; - strlcpy(cmd->u.tc_start.ts_ids_str, src.ls_str, src.ls_len + 1); + strscpy(cmd->u.tc_start.ts_ids_str, src.ls_str, src.ls_len + 1); rc = nrs_tbf_id_list_parse(cmd->u.tc_start.ts_ids_str, strlen(cmd->u.tc_start.ts_ids_str), @@ -2644,7 +2644,7 @@ nrs_tbf_id_rule_init(struct ptlrpc_nrs_policy *policy, if (rule->tr_ids_str == NULL) return -ENOMEM; - strlcpy(rule->tr_ids_str, start->u.tc_start.ts_ids_str, + strscpy(rule->tr_ids_str, start->u.tc_start.ts_ids_str, ids_len); if (!list_empty(&start->u.tc_start.ts_ids)) { diff --git a/lustre/ptlrpc/sec_config.c b/lustre/ptlrpc/sec_config.c index d8469d3..22c877c 100644 --- a/lustre/ptlrpc/sec_config.c +++ b/lustre/ptlrpc/sec_config.c @@ -104,7 +104,7 @@ int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr) return 0; } - strlcpy(buf, str, sizeof(buf)); + strscpy(buf, str, sizeof(buf)); bulk = strchr(buf, '-'); if (bulk) @@ -550,7 +550,7 @@ struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf, OBD_ALLOC_PTR(conf_tgt); if (conf_tgt) { - strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name)); + strscpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name)); sptlrpc_rule_set_init(&conf_tgt->sct_rset); list_add(&conf_tgt->sct_list, &conf->sc_tgts); } @@ -575,9 +575,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname, OBD_ALLOC_PTR(conf); if (conf == NULL) return NULL; - - if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >= - sizeof(conf->sc_fsname)) { + if (strscpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) < 0) { OBD_FREE_PTR(conf); return NULL; } @@ -693,7 +691,7 @@ int sptlrpc_process_config(struct lustre_cfg *lcfg) * is a actual filesystem. */ if (server_name2fsname(target, fsname, NULL)) - strlcpy(fsname, target, sizeof(fsname)); + strscpy(fsname, target, sizeof(fsname)); rc = sptlrpc_parse_rule(param, &rule); if (rc) diff --git a/lustre/quota/qmt_dev.c b/lustre/quota/qmt_dev.c index c810e83..8c7a5ce 100644 --- a/lustre/quota/qmt_dev.c +++ b/lustre/quota/qmt_dev.c @@ -216,9 +216,9 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt, RETURN(-EINVAL); /* record who i am, it might be useful ... */ - rc = strlcpy(qmt->qmt_svname, svname, sizeof(qmt->qmt_svname)); - if (rc >= sizeof(qmt->qmt_svname)) - RETURN(-E2BIG); + rc = strscpy(qmt->qmt_svname, svname, sizeof(qmt->qmt_svname)); + if (rc < 0) + RETURN(rc); /* look-up the obd_device associated with the qmt */ obd = class_name2obd(qmt->qmt_svname); diff --git a/lustre/quota/qsd_lib.c b/lustre/quota/qsd_lib.c index e29a5a7..3fca758 100644 --- a/lustre/quota/qsd_lib.c +++ b/lustre/quota/qsd_lib.c @@ -712,9 +712,9 @@ struct qsd_instance *qsd_init(const struct lu_env *env, char *svname, qsd->qsd_exclusive = excl; /* copy service name */ - if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname)) - >= sizeof(qsd->qsd_svname)) - GOTO(out, rc = -E2BIG); + rc = strscpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname)); + if (rc < 0) + GOTO(out, rc); /* grab reference on osd device */ lu_device_get(&dev->dd_lu_dev); diff --git a/lustre/target/tgt_grant.c b/lustre/target/tgt_grant.c index 37d1ba8..8b6cf48 100644 --- a/lustre/target/tgt_grant.c +++ b/lustre/target/tgt_grant.c @@ -1558,7 +1558,7 @@ int tgt_grant_commit_cb_add(struct thandle *th, struct obd_export *exp, dcb = &tgc->tgc_cb; dcb->dcb_func = tgt_grant_commit_cb; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_grant_commit_cb", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_grant_commit_cb", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/target/tgt_lastrcvd.c b/lustre/target/tgt_lastrcvd.c index e5b850b..8701b98 100644 --- a/lustre/target/tgt_lastrcvd.c +++ b/lustre/target/tgt_lastrcvd.c @@ -566,7 +566,7 @@ static int tgt_new_client_cb_add(struct thandle *th, struct obd_export *exp) dcb = &ccb->lncc_cb; dcb->dcb_func = tgt_cb_new_client; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_cb_new_client", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_cb_new_client", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { @@ -940,7 +940,7 @@ static int tgt_last_commit_cb_add(struct thandle *th, struct lu_target *tgt, dcb = &ccb->llcc_cb; dcb->dcb_func = tgt_cb_last_committed; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_cb_last_committed", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_cb_last_committed", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { -- 1.8.3.1