From: Marcin Slusarz <marcin.slusarz@gmail.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@ZenIV.linux.org.uk>, Christoph Hellwig <hch@lst.de>,
tom@opengridcomputing.com
Subject: Re: [PATCH 1/6] ERR_PTR: if errno value is known at compile time, make sure it's valid
Date: Thu, 22 May 2008 18:03:27 +0200 [thread overview]
Message-ID: <20080522160323.GB8447@joi> (raw)
In-Reply-To: <20080519063852.GA4707@martell.zuzino.mipt.ru>
On Mon, May 19, 2008 at 10:38:52AM +0400, Alexey Dobriyan wrote:
> On Sun, May 18, 2008 at 11:56:53PM +0200, Marcin Slusarz wrote:
> > ERR_PTR is easy to call with wrong argument (positive errno),
> > and this error lead to catastrophic event - oops or kernel panic
> > (dereference of invalid pointer).
> >
> > As most of error handling code paths are rarely tested, this kind of
> > bug can be hidden for years.
> >
> > (Currently there are > 1400 calls of ERR_PTR with constant argument.)
>
> > --- a/include/linux/err.h
> > +++ b/include/linux/err.h
> > @@ -19,11 +19,13 @@
> >
> > #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
> >
> > -static inline void *ERR_PTR(long error)
> > +static inline void *__ERR_PTR(long error)
> > {
> > return (void *) error;
> > }
> >
> > +#define ERR_PTR(error) (BUILD_BUG_ON(__builtin_constant_p(error) && !IS_ERR_VALUE(error)), __ERR_PTR(error))
>
> This needs comment that this construct must be a macro, otherwise gcc
> does something stupid and doesn't break the build (at least in the case
> below).
Thanks, added to new version.
> BTW, I used grep(1) to find it.
http://lkml.org/lkml/2008/5/11/159
>
> [PATCH] xprtrdma: fix ERR_PTR(E typo
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
>
> net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
> +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
> @@ -661,7 +661,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
>
> cma_xprt = rdma_create_xprt(serv, 1);
> if (!cma_xprt)
> - return ERR_PTR(ENOMEM);
> + return ERR_PTR(-ENOMEM);
> xprt = &cma_xprt->sc_xprt;
>
> listen_id = rdma_create_id(rdma_listen_handler, cma_xprt, RDMA_PS_TCP);
>
next prev parent reply other threads:[~2008-05-22 16:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-11 20:12 [PATCH] let ERR_PTR BUILD_BUG_ON when we know its argument is not a valid errno Marcin Slusarz
2008-05-12 23:38 ` Andrew Morton
2008-05-13 20:18 ` Marcin Slusarz
2008-05-18 21:56 ` [PATCH 0/6] Sanity checks for ERR_PTR argument Marcin Slusarz
2008-05-18 21:56 ` [PATCH 1/6] ERR_PTR: if errno value is known at compile time, make sure it's valid Marcin Slusarz
2008-05-19 6:38 ` Alexey Dobriyan
2008-05-22 16:03 ` Marcin Slusarz [this message]
2008-05-18 22:01 ` [PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR Marcin Slusarz
2008-05-18 23:04 ` Johannes Weiner
2008-05-19 5:55 ` Christoph Hellwig
2008-05-19 6:33 ` Al Viro
2008-05-18 22:01 ` [PATCH 3/6] vfs: open_exec cleanup Marcin Slusarz
2008-05-19 5:53 ` Christoph Hellwig
2008-05-22 15:57 ` Marcin Slusarz
2008-05-18 22:03 ` [PATCH 4/6] procfs: switch ERR_PTR to ERR_OR_0_PTR when "error" might be 0 Marcin Slusarz
2008-05-18 22:03 ` [PATCH 5/6] vfs: fix ERR_PTR abuse in generic_readlink Marcin Slusarz
2008-05-18 22:04 ` [PATCH 6/6] ERR_PTR: warn when ERR_PTR parameter is not errno value Marcin Slusarz
2008-05-18 23:13 ` Johannes Weiner
2008-05-19 6:43 ` Alexey Dobriyan
2008-05-19 12:11 ` Johannes Weiner
2008-05-22 16:08 ` Marcin Slusarz
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=20080522160323.GB8447@joi \
--to=marcin.slusarz@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tom@opengridcomputing.com \
--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).