From: Matthew Wilcox <willy@infradead.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, Jordy Zomer <jordy@pwning.systems>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
"Ahmed S. Darwish" <a.darwish@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH] fs: make d_path-like functions all have unsigned size
Date: Tue, 27 Jul 2021 12:19:55 +0100 [thread overview]
Message-ID: <YP/r29mss1BqctYT@casper.infradead.org> (raw)
In-Reply-To: <20210727103625.74961-1-gregkh@linuxfoundation.org>
On Tue, Jul 27, 2021 at 12:36:25PM +0200, Greg Kroah-Hartman wrote:
> When running static analysis tools to find where signed values could
> potentially wrap the family of d_path() functions turn out to trigger a
> lot of mess. In evaluating the code, all of these usages seem safe, but
> pointer math is involved so if a negative number is ever somehow passed
> into these functions, memory can be traversed backwards in ways not
> intended.
> diff --git a/fs/d_path.c b/fs/d_path.c
> index 23a53f7b5c71..7876b741a47e 100644
> --- a/fs/d_path.c
> +++ b/fs/d_path.c
> @@ -182,7 +182,7 @@ static int prepend_path(const struct path *path,
> */
> char *__d_path(const struct path *path,
> const struct path *root,
> - char *buf, int buflen)
> + char *buf, unsigned int buflen)
> {
> DECLARE_BUFFER(b, buf, buflen);
I have questions about the quality of the analysis tool you're using.
struct prepend_buffer {
char *buf;
int len;
};
#define DECLARE_BUFFER(__name, __buf, __len) \
struct prepend_buffer __name = {.buf = __buf + __len, .len = __len}
Why is it not flagging the assignment of an unsigned int buflen to
a signed int len?
> +char *__d_path(const struct path *, const struct path *, char *, unsigned int);
> +char *d_absolute_path(const struct path *, char *, unsigned int);
> +char *d_path(const struct path *, char *, unsigned int);
> +char *dentry_path_raw(const struct dentry *, char *, unsigned int);
> +char *dentry_path(const struct dentry *, char *, unsigned int);
While you're touching these declarations, please name the 'unsigned int'
parameter. I don't care about the others; they are obvious, but an
unsigned int might be flags, a length, or a small grey walrus.
next prev parent reply other threads:[~2021-07-27 11:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 10:36 [PATCH] fs: make d_path-like functions all have unsigned size Greg Kroah-Hartman
2021-07-27 10:49 ` Ahmed S. Darwish
2021-07-27 10:56 ` Greg Kroah-Hartman
2021-07-27 11:19 ` Matthew Wilcox [this message]
2021-07-27 11:51 ` Greg Kroah-Hartman
2021-07-27 14:50 ` Al Viro
2021-07-27 15:07 ` Matthew Wilcox
2021-07-27 15:17 ` Al Viro
2021-07-27 15:31 ` Matthew Wilcox
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=YP/r29mss1BqctYT@casper.infradead.org \
--to=willy@infradead.org \
--cc=a.darwish@linutronix.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ebiggers@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jordy@pwning.systems \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=viro@zeniv.linux.org.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).