From 242b3aa593381c5ed2f425dbfb145bf7ca42e1fc Mon Sep 17 00:00:00 2001 From: Alex Markuze Date: Wed, 2 Jul 2025 11:53:41 +0000 Subject: [PATCH] SAN_STRCPY --- fs/ceph/addr.c | 20 ++++++++++++-------- fs/ceph/dir.c | 6 ++++-- fs/ceph/inode.c | 20 ++++++++++++-------- fs/ceph/mds_client.c | 24 +++++++++++++++++------- fs/ceph/xattr.c | 18 ++++++++++++------ 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 899b965c01acc..8e72926add4ab 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -2390,10 +2390,12 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci, if (*p) goto out; - if (pool_ns) - boutc(cl, "pool %lld ns %.*s no perm cached\n", pool, - (int)pool_ns->len, pool_ns->str); - else + if (pool_ns) { + char result_str[128]; + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), pool_ns->str, (int)pool_ns->len); + boutc(cl, "pool %lld ns %s no perm cached\n", pool, + result_str); + } else boutc(cl, "pool %lld no perm cached\n", pool); down_write(&mdsc->pool_perm_rwsem); @@ -2518,10 +2520,12 @@ out_unlock: out: if (!err) err = have; - if (pool_ns) - boutc(cl, "pool %lld ns %.*s result = %d\n", pool, - (int)pool_ns->len, pool_ns->str, err); - else + if (pool_ns) { + char result_str[128]; + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), pool_ns->str, (int)pool_ns->len); + boutc(cl, "pool %lld ns %s result = %d\n", pool, + result_str, err); + } else boutc(cl, "pool %lld result = %d\n", pool, err); return err; } diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 88fa79f6fe779..4ab16e358571d 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -542,6 +542,7 @@ more: } for (; i < rinfo->dir_nr; i++) { struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i; + char result_str[128]; if (rde->offset < ctx->pos) { pr_warn_client(cl, @@ -554,9 +555,10 @@ more: return -EIO; ctx->pos = rde->offset; - boutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%.*s' %p\n", inode, + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), rde->name, rde->name_len); + boutc(cl, "%p %llx.%llx (%d/%d) -> %llx '%s' %p\n", inode, ceph_vinop(inode), i, rinfo->dir_nr, ctx->pos, - rde->name_len, rde->name, &rde->inode.in); + result_str, &rde->inode.in); if (!dir_emit(ctx, rde->name, rde->name_len, ceph_present_ino(inode->i_sb, le64_to_cpu(rde->inode.in->ino)), diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index dad09100a5949..814f9e9656a0d 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1563,6 +1563,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) if (dir && req->r_op == CEPH_MDS_OP_LOOKUPNAME && test_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags) && !test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) { + char result_str[128]; bool is_nokey = false; struct qstr dname; struct dentry *dn, *parent; @@ -1597,14 +1598,15 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) tvino.ino = le64_to_cpu(rinfo->targeti.in->ino); tvino.snap = le64_to_cpu(rinfo->targeti.in->snapid); retry_lookup: + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), dname.name, dname.len); dn = d_lookup(parent, &dname); - boutc(cl, "d_lookup on parent=%p name=%.*s got %p\n", - parent, dname.len, dname.name, dn); + boutc(cl, "d_lookup on parent=%p name=%s got %p\n", + parent, result_str, dn); if (!dn) { dn = d_alloc(parent, &dname); - boutc(cl, "d_alloc %p '%.*s' = %p\n", parent, - dname.len, dname.name, dn); + boutc(cl, "d_alloc %p '%s' = %p\n", parent, + result_str, dn); if (!dn) { dput(parent); ceph_fname_free_buffer(dir, &oname); @@ -1979,6 +1981,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req, for (i = 0; i < rinfo->dir_nr; i++) { struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i; struct ceph_vino tvino; + char result_str[128]; dname.name = rde->name; dname.len = rde->name_len; @@ -1999,13 +2002,14 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req, retry_lookup: dn = d_lookup(parent, &dname); - boutc(cl, "d_lookup on parent=%p name=%.*s got %p\n", - parent, dname.len, dname.name, dn); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), dname.name, dname.len); + boutc(cl, "d_lookup on parent=%p name=%s got %p\n", + parent, result_str, dn); if (!dn) { dn = d_alloc(parent, &dname); - boutc(cl, "d_alloc %p '%.*s' = %p\n", parent, - dname.len, dname.name, dn); + boutc(cl, "d_alloc %p '%s' = %p\n", parent, + result_str, dn); if (!dn) { boutc(cl, "d_alloc badness\n"); err = -ENOMEM; diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index d437d77396ea6..8d9fc5e18b17c 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -448,6 +448,8 @@ static int parse_reply_info_readdir(void **p, void *end, struct fscrypt_str tname = FSTR_INIT(NULL, 0); struct fscrypt_str oname = FSTR_INIT(NULL, 0); struct ceph_fname fname; + char result_str[128]; + u32 altname_len, _name_len; u8 *altname, *_name; @@ -456,7 +458,8 @@ static int parse_reply_info_readdir(void **p, void *end, ceph_decode_need(p, end, _name_len, bad); _name = *p; *p += _name_len; - boutc(cl, "parsed dir dname '%.*s'\n", _name_len, _name); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), rde->name, rde->name_len); + boutc(cl, "parsed dir dname %s\n", result_str); if (info->hash_order) rde->raw_hash = ceph_str_hash(ci->i_dir_layout.dl_dir_hash, @@ -2738,6 +2741,7 @@ char *ceph_mdsc_build_path(struct ceph_mds_client *mdsc, struct dentry *dentry, int pos; unsigned seq; u64 base; + char result_str[128]; if (!dentry) return ERR_PTR(-EINVAL); @@ -2841,8 +2845,9 @@ retry: *pbase = base; *plen = PATH_MAX - 1 - pos; - boutc(cl, "on %p %d built %llx '%.*s'\n", dentry, d_count(dentry), - base, *plen, path + pos); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), path + pos, *plen); + boutc(cl, "on %p %d built %llx '%s'\n", dentry, d_count(dentry), + base, result_str); return path + pos; } @@ -2906,6 +2911,7 @@ static int set_request_path_attr(struct ceph_mds_client *mdsc, struct inode *rin bool parent_locked) { struct ceph_client *cl = mdsc->fsc->client; + char result_str[128]; int r = 0; if (rinode) { @@ -2915,12 +2921,14 @@ static int set_request_path_attr(struct ceph_mds_client *mdsc, struct inode *rin } else if (rdentry) { r = build_dentry_path(mdsc, rdentry, rdiri, ppath, pathlen, ino, freepath, parent_locked); - boutc(cl, " dentry %p %llx/%.*s\n", rdentry, *ino, *pathlen, *ppath); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), *ppath, *pathlen); + boutc(cl, " dentry %p %llx/%s\n", rdentry, *ino, result_str); } else if (rpath || rino) { *ino = rino; *ppath = rpath; *pathlen = rpath ? strlen(rpath) : 0; - boutc(cl, " path %.*s\n", *pathlen, rpath); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), rpath, *pathlen); + boutc(cl," path %s\n", result_str); } return r; @@ -5210,6 +5218,7 @@ static void handle_lease(struct ceph_mds_client *mdsc, struct ceph_mds_session *session, struct ceph_msg *msg) { + char result_str[128]; struct ceph_client *cl = mdsc->fsc->client; struct super_block *sb = mdsc->fsc->sb; struct inode *inode; @@ -5240,8 +5249,9 @@ static void handle_lease(struct ceph_mds_client *mdsc, /* lookup inode */ inode = ceph_find_inode(sb, vino); - boutc(cl, "%s, ino %llx %p %.*s\n", ceph_lease_op_name(h->action), - vino.ino, inode, dname.len, dname.name); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), dname.name, dname.len); + boutc(cl, "%s, ino %llx %p %s\n", ceph_lease_op_name(h->action), + vino.ino, inode, result_str); mutex_lock(&session->s_mutex); if (!inode) { diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c index 770b8e8c55452..c42cc889a78a4 100644 --- a/fs/ceph/xattr.c +++ b/fs/ceph/xattr.c @@ -571,6 +571,8 @@ static int __set_xattr(struct ceph_inode_info *ci, int flags, int update_xattr, struct ceph_inode_xattr **newxattr) { + char result_str[128]; + char result_str2[128]; struct inode *inode = &ci->netfs.inode; struct ceph_client *cl = ceph_inode_to_client(inode); struct rb_node **p; @@ -659,9 +661,10 @@ static int __set_xattr(struct ceph_inode_info *ci, boutc(cl, "p=%p\n", p); } - boutc(cl, "added %p %llx.%llx xattr %p %.*s=%.*s%s\n", inode, - ceph_vinop(inode), xattr, name_len, name, min(val_len, - MAX_XATTR_VAL_PRINT_LEN), val, + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), name, name_len); + CEPH_SAN_STRNCPY(result_str2, sizeof(result_str2), val, min(val_len, MAX_XATTR_VAL_PRINT_LEN)); + boutc(cl, "added %p %llx.%llx xattr %p %s=%s%s\n", inode, + ceph_vinop(inode), xattr, result_str, result_str2, val_len > MAX_XATTR_VAL_PRINT_LEN ? "..." : ""); return 0; @@ -670,6 +673,7 @@ static int __set_xattr(struct ceph_inode_info *ci, static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci, const char *name) { + char result_str[128]; struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode); struct rb_node **p; struct rb_node *parent = NULL; @@ -690,8 +694,8 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci, p = &(*p)->rb_right; else { int len = min(xattr->val_len, MAX_XATTR_VAL_PRINT_LEN); - - boutc(cl, "%s found %.*s%s\n", name, len, xattr->val, + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), xattr->val, len); + boutc(cl, "%s found %s%s\n", name, result_str, xattr->val_len > len ? "..." : ""); return xattr; } @@ -765,6 +769,7 @@ void __ceph_destroy_xattrs(struct ceph_inode_info *ci) struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode); struct rb_node *p, *tmp; struct ceph_inode_xattr *xattr = NULL; + char result_str[128]; p = rb_first(&ci->i_xattrs.index); @@ -774,7 +779,8 @@ void __ceph_destroy_xattrs(struct ceph_inode_info *ci) xattr = rb_entry(p, struct ceph_inode_xattr, node); tmp = p; p = rb_next(tmp); - boutc(cl, "next p=%p (%.*s)\n", p, xattr->name_len, xattr->name); + CEPH_SAN_STRNCPY(result_str, sizeof(result_str), xattr->name, xattr->name_len); + boutc(cl, "next p=%p (%s)\n", p, result_str); rb_erase(tmp, &ci->i_xattrs.index); __free_xattr(xattr); -- 2.39.5