mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
vfs: replace calling i_op->readlink with vfs_readlink()
Also check d_is_symlink() in callers instead of inode->i_op->readlink because following patches will allow NULL ->readlink for symlinks. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
21
fs/namei.c
21
fs/namei.c
@@ -4668,6 +4668,27 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(generic_readlink);
|
EXPORT_SYMBOL(generic_readlink);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vfs_readlink - copy symlink body into userspace buffer
|
||||||
|
* @dentry: dentry on which to get symbolic link
|
||||||
|
* @buffer: user memory pointer
|
||||||
|
* @buflen: size of buffer
|
||||||
|
*
|
||||||
|
* Does not touch atime. That's up to the caller if necessary
|
||||||
|
*
|
||||||
|
* Does not call security hook.
|
||||||
|
*/
|
||||||
|
int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct inode *inode = d_inode(dentry);
|
||||||
|
|
||||||
|
if (!inode->i_op->readlink)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return inode->i_op->readlink(dentry, buffer, buflen);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(vfs_readlink);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vfs_get_link - get symlink body
|
* vfs_get_link - get symlink body
|
||||||
* @dentry: dentry on which to get symbolic link
|
* @dentry: dentry on which to get symbolic link
|
||||||
|
@@ -3576,10 +3576,10 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
|
|||||||
if (!p)
|
if (!p)
|
||||||
return nfserr_resource;
|
return nfserr_resource;
|
||||||
/*
|
/*
|
||||||
* XXX: By default, the ->readlink() VFS op will truncate symlinks
|
* XXX: By default, vfs_readlink() will truncate symlinks if they
|
||||||
* if they would overflow the buffer. Is this kosher in NFSv4? If
|
* would overflow the buffer. Is this kosher in NFSv4? If not, one
|
||||||
* not, one easy fix is: if ->readlink() precisely fills the buffer,
|
* easy fix is: if vfs_readlink() precisely fills the buffer, assume
|
||||||
* assume that truncation occurred, and return NFS4ERR_RESOURCE.
|
* that truncation occurred, and return NFS4ERR_RESOURCE.
|
||||||
*/
|
*/
|
||||||
nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp,
|
nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp,
|
||||||
(char *)p, &maxcount);
|
(char *)p, &maxcount);
|
||||||
|
@@ -1451,7 +1451,6 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
|||||||
__be32
|
__be32
|
||||||
nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
|
nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
|
||||||
mm_segment_t oldfs;
|
mm_segment_t oldfs;
|
||||||
__be32 err;
|
__be32 err;
|
||||||
int host_err;
|
int host_err;
|
||||||
@@ -1463,10 +1462,9 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
|
|||||||
|
|
||||||
path.mnt = fhp->fh_export->ex_path.mnt;
|
path.mnt = fhp->fh_export->ex_path.mnt;
|
||||||
path.dentry = fhp->fh_dentry;
|
path.dentry = fhp->fh_dentry;
|
||||||
inode = d_inode(path.dentry);
|
|
||||||
|
|
||||||
err = nfserr_inval;
|
err = nfserr_inval;
|
||||||
if (!inode->i_op->readlink)
|
if (!d_is_symlink(path.dentry))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
touch_atime(&path);
|
touch_atime(&path);
|
||||||
@@ -1475,7 +1473,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
oldfs = get_fs(); set_fs(KERNEL_DS);
|
oldfs = get_fs(); set_fs(KERNEL_DS);
|
||||||
host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
|
host_err = vfs_readlink(path.dentry, (char __user *)buf, *lenp);
|
||||||
set_fs(oldfs);
|
set_fs(oldfs);
|
||||||
|
|
||||||
if (host_err < 0)
|
if (host_err < 0)
|
||||||
|
@@ -329,12 +329,14 @@ retry:
|
|||||||
struct inode *inode = d_backing_inode(path.dentry);
|
struct inode *inode = d_backing_inode(path.dentry);
|
||||||
|
|
||||||
error = empty ? -ENOENT : -EINVAL;
|
error = empty ? -ENOENT : -EINVAL;
|
||||||
if (inode->i_op->readlink) {
|
/*
|
||||||
|
* AFS mountpoints allow readlink(2) but are not symlinks
|
||||||
|
*/
|
||||||
|
if (d_is_symlink(path.dentry) || inode->i_op->readlink) {
|
||||||
error = security_inode_readlink(path.dentry);
|
error = security_inode_readlink(path.dentry);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
touch_atime(&path);
|
touch_atime(&path);
|
||||||
error = inode->i_op->readlink(path.dentry,
|
error = vfs_readlink(path.dentry, buf, bufsiz);
|
||||||
buf, bufsiz);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path_put(&path);
|
path_put(&path);
|
||||||
|
@@ -287,7 +287,7 @@ xfs_readlink_by_handle(
|
|||||||
return PTR_ERR(dentry);
|
return PTR_ERR(dentry);
|
||||||
|
|
||||||
/* Restrict this handle operation to symlinks only. */
|
/* Restrict this handle operation to symlinks only. */
|
||||||
if (!d_inode(dentry)->i_op->readlink) {
|
if (!d_is_symlink(dentry)) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
goto out_dput;
|
goto out_dput;
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ xfs_readlink_by_handle(
|
|||||||
goto out_dput;
|
goto out_dput;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = d_inode(dentry)->i_op->readlink(dentry, hreq->ohandle, olen);
|
error = vfs_readlink(dentry, hreq->ohandle, olen);
|
||||||
|
|
||||||
out_dput:
|
out_dput:
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
|
@@ -2935,6 +2935,7 @@ extern int vfs_lstat(const char __user *, struct kstat *);
|
|||||||
extern int vfs_fstat(unsigned int, struct kstat *);
|
extern int vfs_fstat(unsigned int, struct kstat *);
|
||||||
extern int vfs_fstatat(int , const char __user *, struct kstat *, int);
|
extern int vfs_fstatat(int , const char __user *, struct kstat *, int);
|
||||||
extern const char *vfs_get_link(struct dentry *, struct delayed_call *);
|
extern const char *vfs_get_link(struct dentry *, struct delayed_call *);
|
||||||
|
extern int vfs_readlink(struct dentry *, char __user *, int);
|
||||||
|
|
||||||
extern int __generic_block_fiemap(struct inode *inode,
|
extern int __generic_block_fiemap(struct inode *inode,
|
||||||
struct fiemap_extent_info *fieinfo,
|
struct fiemap_extent_info *fieinfo,
|
||||||
|
Reference in New Issue
Block a user