linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* harden against corrupt symlinks
@ 2005-05-31 23:02 Mike Waychison
  2005-06-01  8:15 ` Andreas Dilger
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Waychison @ 2005-05-31 23:02 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

Hi Al,

We've hit the situation a few times where a corrupt symlink could easily 
oops the kernel.  The problem was tracked down to an older e2fsutils 
that didn't do much sanity checking on symlinks during a fsck.  This 
patch uses strnlen when reading in the symlink and ensures that it 
doesn't exceed PATH_MAX.

Would you accept this kind of 'hardening'?

Signed-off-by: Mike Waychison <mikew@google.com>

[-- Attachment #2: symlink_run_off.patch --]
[-- Type: text/plain, Size: 707 bytes --]

--- 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))

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-18 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-31 23:02 harden against corrupt symlinks Mike Waychison
2005-06-01  8:15 ` Andreas Dilger
2006-08-11 22:48   ` Andrew Morton
2006-08-18  6:27     ` Andreas Dilger
2006-08-18 12:49       ` Dave Kleikamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).