From: Andreas Dilger <adilger@clusterfs.com>
To: Mike Waychison <mikew@google.com>
Cc: viro@parcelfarce.linux.theplanet.co.uk, linux-fsdevel@vger.kernel.org
Subject: Re: harden against corrupt symlinks
Date: Wed, 1 Jun 2005 02:15:48 -0600 [thread overview]
Message-ID: <20050601081548.GU14004@schnapps.adilger.int> (raw)
In-Reply-To: <429CED16.2040406@google.com>
On May 31, 2005 16:02 -0700, Mike Waychison wrote:
> 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>
Andrew Morton suggested a very similar fix 3 years ago to this list:
Subject: Re: ext3 -> crash -> fsck -> readlink -> oops
I thought it made it into the kernel then, but I guess not.
> --- 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))
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
next prev parent reply other threads:[~2005-06-01 8:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-31 23:02 harden against corrupt symlinks Mike Waychison
2005-06-01 8:15 ` Andreas Dilger [this message]
2006-08-11 22:48 ` Andrew Morton
2006-08-18 6:27 ` Andreas Dilger
2006-08-18 12:49 ` Dave Kleikamp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050601081548.GU14004@schnapps.adilger.int \
--to=adilger@clusterfs.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mikew@google.com \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).