Re: [PATCH 12/19] pramfs: symlink operations
From: Al Viro
Date: Sat Sep 07 2013 - 10:41:31 EST
On Sat, Sep 07, 2013 at 10:29:15AM +0200, Marco Stornelli wrote:
> +static int pram_readlink(struct dentry *dentry, char __user *buffer, int buflen)
> +{
> + struct inode *inode = dentry->d_inode;
> + struct super_block *sb = inode->i_sb;
> + u64 block;
> + char *blockp;
> +
> + block = pram_find_data_block(inode, 0);
> + blockp = pram_get_block(sb, block);
> + return vfs_readlink(dentry, buffer, buflen, blockp);
> +}
> +static void *pram_follow_link(struct dentry *dentry, struct nameidata *nd)
> +{
> + struct inode *inode = dentry->d_inode;
> + struct super_block *sb = inode->i_sb;
> + off_t block;
> + int status;
> + char *blockp;
> +
> + block = pram_find_data_block(inode, 0);
> + blockp = pram_get_block(sb, block);
> + status = vfs_follow_link(nd, blockp);
> + return ERR_PTR(status);
> +}
Just nd_set_link(nd, blockp) instead of that vfs_follow_link() and be
done with that; that way you can use generic_readlink() instead of
pram_readlink() *and* get lower stack footprint on traversing them.
BTW, where's the error checking? pram_get_block()/pram_find_data_block()
seem to assume that fs image isn't corrupted and if it is... that code
will happily dereference any address. At least range checks of some sort
in pram_get_block() (and checking if it has failed) would be a good idea...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/