From: Dave Kleikamp <shaggy@austin.ibm.com>
To: Andreas Dilger <adilger@clusterfs.com>
Cc: Andrew Morton <akpm@osdl.org>, Mike Waychison <mikew@google.com>,
viro@parcelfarce.linux.theplanet.co.uk,
linux-fsdevel@vger.kernel.org, Edward Falk <efalk@google.com>,
Zach Brown <zab@zabbo.net>, Neil Brown <neilb@cse.unsw.edu.au>
Subject: Re: harden against corrupt symlinks
Date: Fri, 18 Aug 2006 07:49:45 -0500 [thread overview]
Message-ID: <1155905385.7255.13.camel@kleikamp.austin.ibm.com> (raw)
In-Reply-To: <20060818062753.GD6634@schatzie.adilger.int>
On Fri, 2006-08-18 at 00:27 -0600, Andreas Dilger wrote:
> On Aug 11, 2006 15:48 -0700, Andrew Morton wrote:
> >
> > Given that this is the VFS correcting for filesystem misbehaviour, it would
> > seem to make sense to perform this correction at a low level, immediately
> > after the filesytem driver has returned us the pathname component. An
> > apparently-obvious way of doing this is to wrap ->follow_link. Can anyone
> > think of a smarter way?
>
> #define PATH_MAX 4096 /* # chars in a path name including nul */
>
> One possibility is for the case of long symlinks to always set the last byte
> of the page to NUL to ensure that the link is terminated. This appears
> easily doable by having page_getlink() do the NUL termination after kmap()
> but before returning, something like:
>
> static char *page_getlink(struct dentry * dentry, struct page **ppage)
> {
> char *link;
> page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage,
> NULL);
> if (IS_ERR(page))
> goto sync_fail;
> wait_on_page_locked(page);
> if (!PageUptodate(page))
> goto async_fail;
> *ppage = page;
> - return kmap(page);
> + link = kmap(page);
> + /* PATH_MAX is strictly <= PAGE_SIZE */
> + link[PATH_MAX - 1] = '\0';
> + return link;
This seems reasonable.
>
>
> Many of the other filesystems that don't use page_follow_link_light()
> already do NUL termination themselves.
>
> nfs_follow_link() is very similar, but not identical and needs the same fix.
jfs_follow_link() too. :-)
> ocfs2_page_getlink() is an exact duplicate of page_getlink() and the bug
> duplication could be avoided if page_getlink() was exported. Otherwise it
> needs the same fix.
>
>
> I _think_ PATH_MAX is the right thing here (instead of PAGE_SIZE), since
> the caller expects at most PATH_MAX in the returned link, and PAGE_SIZE
> may be considerably larger. I don't think PATH_MAX will ever be larger
> than PAGE_SIZE. We could also use min(PAGE_SIZE, PATH_MAX) and it would
> be resolved at compile time, but it seems wishy-washy to me.
>
> The other option is to actually get the link length out of the filesystem
> itself, and avoid strlen(link) entirely, but that is a more complex change.
Is it? Is there any file system where the link length is not i_size?
--
David Kleikamp
IBM Linux Technology Center
prev parent reply other threads:[~2006-08-18 12:49 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
2006-08-11 22:48 ` Andrew Morton
2006-08-18 6:27 ` Andreas Dilger
2006-08-18 12:49 ` Dave Kleikamp [this message]
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=1155905385.7255.13.camel@kleikamp.austin.ibm.com \
--to=shaggy@austin.ibm.com \
--cc=adilger@clusterfs.com \
--cc=akpm@osdl.org \
--cc=efalk@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mikew@google.com \
--cc=neilb@cse.unsw.edu.au \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
--cc=zab@zabbo.net \
/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).