Skip to contentSkip to conversation

Strangeness in generic_readlink()

DISCUSSION Jan Kara 1 participant 1 message Jul 15, 2015 VFS

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

Hello,

Coverity has drawn my attention to a strange code in generic_readlink(). We do there:

        const char *link = inode->i_link;

        if (!link) {
                link = inode->i_op->follow_link(dentry, &cookie);
                if (IS_ERR(link))
                        return PTR_ERR(link);
        }
        res = readlink_copy(buffer, buflen, link);
        if (inode->i_op->put_link)
                inode->i_op->put_link(inode, cookie);

However when inode->i_link is set and the inode also has put_link method, we would pass uninitialized cookie to put_link.

Now if I understand the code right, each inode is supposed to use either i_link or cookies so this shouldn't really happen but IMHO it's unnecessarily fragile. I'd prefer to call put_link only if follow_link was called in generic_readlink(). Thoughts?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR