From: Andrew Morton <akpm@linux-foundation.org>
To: "Changli Gao" <xiaosuo@gmail.com>
Cc: linux-kernel@vger.kernel.org, Jens Axboe <jens.axboe@oracle.com>
Subject: Re: BUG: file descriptors leak when sys_pipe failed with -EFAULT
Date: Thu, 13 Dec 2007 13:21:48 -0800 [thread overview]
Message-ID: <20071213132148.8f18a107.akpm@linux-foundation.org> (raw)
In-Reply-To: <412e6f7f0712130434h93ce8ffi9f7d91ea1589f84c@mail.gmail.com>
On Thu, 13 Dec 2007 20:34:11 +0800
"Changli Gao" <xiaosuo@gmail.com> wrote:
> If an invalid address is passed to system call pipe as argument, file
> descriptors will leak.
Yup. I added linux-kernel to cc.
> System call pipe is implemented as following on most architectures:
>
> int fd[2];
> int error;
>
> error = do_pipe(fd);
> if (!error) {
> if (copy_to_user(fildes, fd, 2*sizeof(int)))
> error = -EFAULT;
> }
> return error;
>
> Invalid memory address makes copy_to_user failed. But the descriptors
> allocated for the pipe will be left open.
> A workaround fix will be like this:
>
> int fd[2];
> int error;
>
> error = do_pipe(fd);
> if (!error) {
> if (copy_to_user(fildes, fd, 2*sizeof(int))) {
> sys_close(fd[0]);
> sys_close(fd[1]);
> error = -EFAULT;
> }
> }
> return error;
>
> I don't understand the others architectures(such as
> sh/sh64/mips/sparc/sparc64) which implement pipe in the other ways,
> so I just indicate this bug and provide my fixing way instead of
> patching it.
The consequences of this are that the application may eventually run out of
file descriptors and they will be cleaned up when the application exits
anyway, so it isn't terribly serious.
However it does seem fairly dumb of us to leave the fds open given that
at least one or possibly both of the file descriptors are unknown to the
application anyway. Probably it'd be better to close them off immediately.
This would be an application-visible change: subsequent open()s will return
lower-numbered descriptors than they do at present. That shouldn't matter.
next parent reply other threads:[~2007-12-13 21:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <412e6f7f0712130434h93ce8ffi9f7d91ea1589f84c@mail.gmail.com>
2007-12-13 21:21 ` Andrew Morton [this message]
2007-12-13 21:50 ` BUG: file descriptors leak when sys_pipe failed with -EFAULT Jens Axboe
2007-12-14 11:46 ` Herbert Xu
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=20071213132148.8f18a107.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xiaosuo@gmail.com \
/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