* [PATCH] posix_acl: fix reference leaks in posix_acl_create
@ 2015-01-27 6:16 Omar Sandoval
2015-01-28 17:09 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: Omar Sandoval @ 2015-01-27 6:16 UTC (permalink / raw)
To: Alexander Viro, Christoph Hellwig, linux-fsdevel, linux-kernel
Cc: Omar Sandoval
get_acl gets a reference which we must release in the error cases.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
---
fs/posix_acl.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 0855f77..f8f3cc2 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -555,28 +555,31 @@ posix_acl_create(struct inode *dir, umode_t *mode,
p = get_acl(dir, ACL_TYPE_DEFAULT);
if (IS_ERR(p)) {
if (p == ERR_PTR(-EOPNOTSUPP))
goto apply_umask;
return PTR_ERR(p);
}
if (!p)
goto apply_umask;
*acl = posix_acl_clone(p, GFP_NOFS);
- if (!*acl)
+ if (!*acl) {
+ posix_acl_release(p);
return -ENOMEM;
+ }
ret = posix_acl_create_masq(*acl, mode);
if (ret < 0) {
posix_acl_release(*acl);
+ posix_acl_release(p);
return -ENOMEM;
}
if (ret == 0) {
posix_acl_release(*acl);
*acl = NULL;
}
if (!S_ISDIR(*mode)) {
posix_acl_release(p);
*default_acl = NULL;
--
2.2.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] posix_acl: fix reference leaks in posix_acl_create
2015-01-27 6:16 [PATCH] posix_acl: fix reference leaks in posix_acl_create Omar Sandoval
@ 2015-01-28 17:09 ` Christoph Hellwig
2015-02-02 7:55 ` Omar Sandoval
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2015-01-28 17:09 UTC (permalink / raw)
To: Omar Sandoval
Cc: Alexander Viro, Christoph Hellwig, linux-fsdevel, linux-kernel
On Mon, Jan 26, 2015 at 10:16:53PM -0800, Omar Sandoval wrote:
> get_acl gets a reference which we must release in the error cases.
>
> Signed-off-by: Omar Sandoval <osandov@osandov.com>
Looks good, but at this point goto-based unwinding might be in order.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] posix_acl: fix reference leaks in posix_acl_create
2015-01-28 17:09 ` Christoph Hellwig
@ 2015-02-02 7:55 ` Omar Sandoval
2015-02-02 14:19 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: Omar Sandoval @ 2015-02-02 7:55 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Alexander Viro, linux-fsdevel, linux-kernel
On Wed, Jan 28, 2015 at 06:09:52PM +0100, Christoph Hellwig wrote:
> On Mon, Jan 26, 2015 at 10:16:53PM -0800, Omar Sandoval wrote:
> > get_acl gets a reference which we must release in the error cases.
> >
> > Signed-off-by: Omar Sandoval <osandov@osandov.com>
>
> Looks good, but at this point goto-based unwinding might be in order.
Hi, Christoph,
There are already a couple of return paths in posix_acl_create, and
there are only these two error cases, so I think gotos might actually
make the code more confusing. In any case, here's an idea:
posix_acl: fix reference leaks in posix_acl_create
get_acl gets a reference which we must release in the error cases.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 0855f77..515d315 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -564,13 +564,11 @@ posix_acl_create(struct inode *dir, umode_t *mode,
*acl = posix_acl_clone(p, GFP_NOFS);
if (!*acl)
- return -ENOMEM;
+ goto no_mem;
ret = posix_acl_create_masq(*acl, mode);
- if (ret < 0) {
- posix_acl_release(*acl);
- return -ENOMEM;
- }
+ if (ret < 0)
+ goto no_mem_clone;
if (ret == 0) {
posix_acl_release(*acl);
@@ -591,6 +589,12 @@ no_acl:
*default_acl = NULL;
*acl = NULL;
return 0;
+
+no_mem_clone:
+ posix_acl_release(*acl);
+no_mem:
+ posix_acl_release(p);
+ return -ENOMEM;
}
EXPORT_SYMBOL_GPL(posix_acl_create);
--
Omar
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] posix_acl: fix reference leaks in posix_acl_create
2015-02-02 7:55 ` Omar Sandoval
@ 2015-02-02 14:19 ` Christoph Hellwig
2015-02-09 5:45 ` [PATCH v2] " Omar Sandoval
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2015-02-02 14:19 UTC (permalink / raw)
To: Omar Sandoval; +Cc: Alexander Viro, linux-fsdevel, linux-kernel
On Sun, Feb 01, 2015 at 11:55:02PM -0800, Omar Sandoval wrote:
> There are already a couple of return paths in posix_acl_create, and
> there are only these two error cases, so I think gotos might actually
> make the code more confusing. In any case, here's an idea:
>
> posix_acl: fix reference leaks in posix_acl_create
>
> get_acl gets a reference which we must release in the error cases.
>
> Signed-off-by: Omar Sandoval <osandov@osandov.com>
Thanks, this one looks good to me.
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] posix_acl: fix reference leaks in posix_acl_create
2015-02-02 14:19 ` Christoph Hellwig
@ 2015-02-09 5:45 ` Omar Sandoval
0 siblings, 0 replies; 5+ messages in thread
From: Omar Sandoval @ 2015-02-09 5:45 UTC (permalink / raw)
To: Alexander Viro, Christoph Hellwig
Cc: linux-fsdevel, linux-kernel, Omar Sandoval
get_acl gets a reference which we must release in the error cases.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
---
Hi, Al,
I'm guessing you're the one to take this one? Just a resend with the
proper format and Christoph's Reviewed-by.
Thanks!
fs/posix_acl.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 0855f77..515d315 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -564,13 +564,11 @@ posix_acl_create(struct inode *dir, umode_t *mode,
*acl = posix_acl_clone(p, GFP_NOFS);
if (!*acl)
- return -ENOMEM;
+ goto no_mem;
ret = posix_acl_create_masq(*acl, mode);
- if (ret < 0) {
- posix_acl_release(*acl);
- return -ENOMEM;
- }
+ if (ret < 0)
+ goto no_mem_clone;
if (ret == 0) {
posix_acl_release(*acl);
@@ -591,6 +589,12 @@ no_acl:
*default_acl = NULL;
*acl = NULL;
return 0;
+
+no_mem_clone:
+ posix_acl_release(*acl);
+no_mem:
+ posix_acl_release(p);
+ return -ENOMEM;
}
EXPORT_SYMBOL_GPL(posix_acl_create);
--
2.3.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-09 5:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-27 6:16 [PATCH] posix_acl: fix reference leaks in posix_acl_create Omar Sandoval
2015-01-28 17:09 ` Christoph Hellwig
2015-02-02 7:55 ` Omar Sandoval
2015-02-02 14:19 ` Christoph Hellwig
2015-02-09 5:45 ` [PATCH v2] " Omar Sandoval
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).