diff --git a/qtfs/qtfs/proc.c b/qtfs/qtfs/proc.c index 8077653192952227585ead0359268a74b0a11477..cc90cd3f6644e1ac94da6589272dfdc0556943f9 100644 --- a/qtfs/qtfs/proc.c +++ b/qtfs/qtfs/proc.c @@ -130,7 +130,7 @@ struct dentry *qtfs_proc_lookup(struct inode *parent_inode, struct dentry *child memset(cpath, 0, MAX_PATH_LEN); memset(tmp, 0, MAX_PATH_LEN); - if (qtfs_fullname(cpath, child_dentry) < 0) { + if (qtfs_fullname(cpath, child_dentry, MAX_PATH_LEN) < 0) { qtfs_err("%s: failed to get fullname", __func__); goto remote; } @@ -193,7 +193,7 @@ const char *qtfs_proc_getlink(struct dentry *dentry, memset(path, 0, MAX_PATH_LEN); memset(tmp, 0, MAX_PATH_LEN); - if (qtfs_fullname(path, dentry) < 0) { + if (qtfs_fullname(path, dentry, MAX_PATH_LEN) < 0) { qtfs_info("[%s]: get path failed", __func__); goto link_remote; } @@ -254,7 +254,7 @@ int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, memset(tmp, 0, MAX_PATH_LEN); memset(local_path, 0, MAX_PATH_LEN); - if (qtfs_fullname(cpath, path->dentry) < 0) { + if (qtfs_fullname(cpath, path->dentry, MAX_PATH_LEN) < 0) { qtfs_err("%s: failed to get fullname", __func__); goto remote; } diff --git a/qtfs/qtfs/qtfs-mod.h b/qtfs/qtfs/qtfs-mod.h index 6be61fa060206e0a5a3bc24ed7c664f5e405ae70..ed37c6ef7b63c973462d5e8ad3aca6497ec1b7f2 100644 --- a/qtfs/qtfs/qtfs-mod.h +++ b/qtfs/qtfs/qtfs-mod.h @@ -111,7 +111,7 @@ struct qtmiss_ops { char str[32]; }; -static inline int qtfs_fullname(char *fullname, struct dentry *d) +static inline int qtfs_fullname(char *fullname, struct dentry *d, size_t buflen) { struct qtfs_fs_info *fsinfo = NULL; int len = 0; @@ -122,6 +122,11 @@ static inline int qtfs_fullname(char *fullname, struct dentry *d) qtfs_info("%s: get dentry fullname NULL\n", __func__); return -1; } + if (buflen < MAX_PATH_LEN) { + qtfs_err("%s: failed to get fullname dure to small buflen:%d\n", __func__, buflen); + return -1; + } + name = __getname(); if (!name) { return -1; @@ -158,8 +163,8 @@ static inline int qtfs_fullname(char *fullname, struct dentry *d) return len; } -#define QTFS_FULLNAME(fullname, d) \ - if (qtfs_fullname(fullname, d)<0) { \ +#define QTFS_FULLNAME(fullname, d, buflen) \ + if (qtfs_fullname(fullname, d, buflen)<0) { \ qtfs_err("qtfs fullname failed\n"); \ qtfs_conn_put_param(pvar); \ return -EINVAL; \ diff --git a/qtfs/qtfs/sb.c b/qtfs/qtfs/sb.c index 44389f4c7c187855e5ec6ff47795c495808a9ee5..a48f5d31ab7a031acecf98838885cf771b1a20b8 100644 --- a/qtfs/qtfs/sb.c +++ b/qtfs/qtfs/sb.c @@ -47,7 +47,7 @@ int qtfs_statfs(struct dentry *dentry, struct kstatfs *buf) req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); rsp = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_RECV); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); rsp = qtfs_remote_run(pvar, QTFS_REQ_STATFS, QTFS_SEND_SIZE(struct qtreq_statfs, req->path)); if (IS_ERR_OR_NULL(rsp)) { qtfs_conn_put_param(pvar); @@ -139,7 +139,7 @@ int qtfs_readdir(struct file *filp, struct dir_context *ctx) req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); rsp = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_RECV); - QTFS_FULLNAME(req->path, filp->f_path.dentry); + QTFS_FULLNAME(req->path, filp->f_path.dentry, sizeof(req->path)); req->count = sizeof(rsp->dirent); req->pos = ctx->pos; @@ -196,7 +196,7 @@ int qtfs_open(struct inode *inode, struct file *file) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, file->f_path.dentry); + QTFS_FULLNAME(req->path, file->f_path.dentry, sizeof(req->path)); req->flags = file->f_flags; req->mode = file->f_mode; @@ -620,7 +620,7 @@ long qtfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (!fullname) return -ENOMEM; memset(fullname, 0, MAX_PATH_LEN); - qtfs_fullname(fullname, filp->f_path.dentry); + qtfs_fullname(fullname, filp->f_path.dentry, MAX_PATH_LEN); qtfs_err("qtfs ioctl get not support cmd:%d file:%s TCGETS:%d", cmd, fullname, TCGETS); kfree(fullname); return -EOPNOTSUPP; @@ -862,7 +862,7 @@ int qtfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); req->mode = mode; rsp = qtfs_remote_run(pvar, QTFS_REQ_MKDIR, QTFS_SEND_SIZE(struct qtreq_mkdir, req->path)); @@ -902,7 +902,7 @@ int qtfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool exc } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); req->mode = mode; req->excl = excl; @@ -946,7 +946,7 @@ int qtfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); req->mode = mode; req->dev = dev; @@ -1048,7 +1048,7 @@ struct dentry *qtfs_lookup(struct inode *parent_inode, struct dentry *child_dent } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - ret = qtfs_fullname(req->fullname, child_dentry); + ret = qtfs_fullname(req->fullname, child_dentry, sizeof(req->fullname)); if (ret < 0) { qtfs_err("qtfs lookup get fullname failed, too many path layers, <%s>!", req->fullname); goto err_end; @@ -1092,7 +1092,7 @@ int qtfs_rmdir(struct inode *dir, struct dentry *dentry) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); rsp = qtfs_remote_run(pvar, QTFS_REQ_RMDIR, QTFS_SEND_SIZE(struct qtreq_rmdir, req->path)); if (IS_ERR_OR_NULL(rsp)) { @@ -1128,7 +1128,7 @@ int qtfs_unlink(struct inode *dir, struct dentry *dentry) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); qtfs_info("qtfs unlink %s.\n", req->path); rsp = qtfs_remote_run(pvar, QTFS_REQ_UNLINK, QTFS_SEND_SIZE(struct qtreq_unlink, req->path)); @@ -1164,9 +1164,9 @@ int qtfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_d } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, old_dentry); + QTFS_FULLNAME(req->path, old_dentry, sizeof(req->path)); req->d.oldlen = strlen(req->path) + 1; - QTFS_FULLNAME(req->path + req->d.oldlen, new_dentry); + QTFS_FULLNAME(req->path + req->d.oldlen, new_dentry, sizeof(req->path) - req->d.oldlen); req->d.newlen = strlen(req->path + req->d.oldlen) + 1; rsp = qtfs_remote_run(pvar, QTFS_REQ_LINK, sizeof(struct qtreq_link) - sizeof(req->path) + req->d.newlen + req->d.oldlen); if (IS_ERR_OR_NULL(rsp)) { @@ -1209,7 +1209,7 @@ int qtfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); req->d.newlen = strlen(req->path) + 1; if (req->d.newlen + strlen(symname) + 1 > sizeof(req->path)) { qtfs_conn_put_param(pvar); @@ -1259,7 +1259,7 @@ int qtfs_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsi } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, path->dentry); + QTFS_FULLNAME(req->path, path->dentry, sizeof(req->path)); req->request_mask = req_mask; req->query_flags = flags; mnt_path = qtfs_mountpoint_path_init(path->dentry, (struct path*)path, req->path); @@ -1308,7 +1308,7 @@ int qtfs_setattr(struct dentry *dentry, struct iattr *attr) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - QTFS_FULLNAME(req->path, dentry); + QTFS_FULLNAME(req->path, dentry, sizeof(req->path)); req->attr = *attr; req->attr.ia_file = NULL; qtfs_info("iattr iavalid:%u mode:0x%o size:%lld file:0x%lx\n", @@ -1355,7 +1355,7 @@ const char *qtfs_getlink(struct dentry *dentry, } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - if (qtfs_fullname(req->path, dentry) < 0) { + if (qtfs_fullname(req->path, dentry, sizeof(req->path)) < 0) { qtfs_err("qtfs fullname failed\n"); qtfs_conn_put_param(pvar); return ERR_PTR(-EINVAL); @@ -1416,14 +1416,14 @@ int qtfs_rename(struct inode *old_dir, struct dentry *old_dentry, } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - req->d.oldlen = qtfs_fullname(req->path, old_dentry); + req->d.oldlen = qtfs_fullname(req->path, old_dentry, sizeof(req->path)); if (req->d.oldlen < 0) { qtfs_err("qtfs fullname failed\n"); qtfs_conn_put_param(pvar); return -EINVAL; } req->d.oldlen += 1; - req->d.newlen = qtfs_fullname(&req->path[req->d.oldlen], new_dentry); + req->d.newlen = qtfs_fullname(&req->path[req->d.oldlen], new_dentry, sizeof(req->path) - req->d.oldlen); if (req->d.newlen < 0) { qtfs_err("qtfs fullname failed\n"); qtfs_conn_put_param(pvar); diff --git a/qtfs/qtfs/syscall.c b/qtfs/qtfs/syscall.c index 5d4d38b2f615d9208393500fd734f361fd925b19..64c26923d2e2cb5b54837b27a0967ba74d23b387 100644 --- a/qtfs/qtfs/syscall.c +++ b/qtfs/qtfs/syscall.c @@ -137,7 +137,7 @@ int qtfs_epoll_ctl_remote(int op, int fd, struct epoll_event __user * event) goto end; } memset(fullname, 0, MAX_PATH_LEN); - if (qtfs_fullname(fullname, file->f_path.dentry) < 0) { + if (qtfs_fullname(fullname, file->f_path.dentry, MAX_PATH_LEN) < 0) { qtfs_err("qtfs fullname failed\n"); kfree(fullname); ret = -1; @@ -246,7 +246,7 @@ int qtfs_dir_to_qtdir(char *dir, char *qtdir) if (strcmp(path.mnt->mnt_sb->s_type->name, QTFS_FSTYPE_NAME)) { strcpy(qtdir, dir); } else { - ret = qtfs_fullname(qtdir, path.dentry); + ret = qtfs_fullname(qtdir, path.dentry, len); } path_put(&path); return ret; diff --git a/qtfs/qtfs/xattr.c b/qtfs/qtfs/xattr.c index 2dfb9fd48d91f28bd762becfcec0857442f8ab79..1ad484af87bc4baffcd687ba5fc6aaab7f564f7e 100644 --- a/qtfs/qtfs/xattr.c +++ b/qtfs/qtfs/xattr.c @@ -39,7 +39,7 @@ ssize_t qtfs_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - if (qtfs_fullname(req->path, dentry) < 0) { + if (qtfs_fullname(req->path, dentry, sizeof(req->path)) < 0) { qtfs_err("qtfs fullname failed"); qtfs_conn_put_param(pvar); return 0; @@ -142,7 +142,7 @@ static int qtfs_xattr_set(const struct xattr_handler *handler, return -ENOENT; } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - if (qtfs_fullname(req->buf, dentry) < 0) { + if (qtfs_fullname(req->buf, dentry, sizeof(req->buf)) < 0) { qtfs_err("xattr set get fullname failed."); qtfs_conn_put_param(pvar); return -EFAULT; @@ -197,7 +197,7 @@ static int qtfs_xattr_get(const struct xattr_handler *handler, } req = pvar->conn_ops->get_conn_msg_buf(pvar, QTFS_SEND); - if (qtfs_fullname(req->path, dentry) < 0) { + if (qtfs_fullname(req->path, dentry, sizeof(req->path)) < 0) { qtfs_err("qtfs fullname failed"); qtfs_conn_put_param(pvar); return 0;