--- linux-2.6/fs/namei.c 2005-05-24 11:13:09.000000000 -0700 +++ linux-2.6/fs/namei.c 2005-05-24 11:13:12.000000000 -0700 @@ -1936,7 +1936,12 @@ int vfs_readlink(struct dentry *dentry, if (IS_ERR(link)) goto out; - len = strlen(link); + len = strnlen(link, PATH_MAX); + if (len == PATH_MAX) { + len = -ENAMETOOLONG; + goto out; + } + if (len > (unsigned) buflen) len = buflen; if (copy_to_user(buffer, link, len)) @@ -1953,6 +1958,11 @@ __vfs_follow_link(struct nameidata *nd, if (IS_ERR(link)) goto fail; + if (strnlen(link, PATH_MAX) == PATH_MAX) { + link = ERR_PTR(-ENAMETOOLONG); + goto fail; + } + if (*link == '/') { path_release(nd); if (!walk_init_root(link, nd))