:Return proper error value on failure of dentry_open
Subsystems (3)
PATCH 1/1 :Return proper error value on failure of dentry_open
dentry_open can return error value on error.
Check that value before calling fput & return proper error value
--- security/integrity/ima/ima_main.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
security/integrity/ima/ima_main.c +2 -2
@@ -201,10 +201,10 @@ int ima_path_check(struct path *path, int mask) } out:mutex_unlock (&iint->mutex); -if (file) +if (IS_ERR (file))fput (file);kref_put (&iint->refcount, iint_free); -return 0 ; +return rc; } static int process_measurement(struct file *file, const unsigned char *filename,
Signature · 1 line
1.6.0
security/integrity/ima/ima_main.c int ima_path_check(struct path *path, int mask) · line 205
Quoted 9 lines · vibi sreenivasan
security/integrity/ima/ima_main.c +1
-1@@ -201,10 +201,10 @@ int ima_path_check(struct path *path, int mask) } out:mutex_unlock (&iint->mutex); -if (file) +if (IS_ERR (file))fput (file);
This makes no sense at all. If it is IS_ERR, i.e. some negative value, you don't want to pass it to fput. 'if (file)' was perfectly correct.
hi,
thanks for pointing that out.
Quoted 5 lines
security/integrity/ima/ima_main.c int ima_path_check(struct path *path, int mask) · line 205
Quoted 5 lines
out:
security/integrity/ima/ima_main.c +1
-1mutex_unlock (&iint->mutex); -if (file) +if (IS_ERR (file))fput (file);
extremely sorry it was
if(!IS_ERR(file)) fput(file);
i will send that patch again
Quoted 3 lines
This makes no sense at all. If it is
IS_ERR, i.e. some negative value, you don't want to pass it to fput. 'if (file)' was perfectly correct.
if(file) is true for file != 0 , ie even if file is a -ve error value.
so while fput dereference file ,this can cause a bug to be triggered.
I actually had one.
Thanks & regards
vibi sreenivasan
Quoted 1 line
PATCH 1/1 :RESEND : Return proper error value on failure of dentry_open
In reply to Jiri Slaby dentry_open can return error value on error.
Check that value before calling fput & return proper error value
--- security/integrity/ima/ima_main.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
security/integrity/ima/ima_main.c +2 -2
@@ -201,10 +201,10 @@ int ima_path_check(struct path *path, int mask) } out:mutex_unlock (&iint->mutex); -if (file) +if (!IS_ERR (file))fput (file);kref_put (&iint->refcount, iint_free); -return 0 ; +return rc; } static int process_measurement(struct file *file, const unsigned char *filename,
Signature · 1 line
1.6.0
Re: [PATCH]:RESEND : Return proper error value on failure of dentry_open
security/integrity/ima/ima_main.c int ima_path_check(struct path *path, int mask) · line 205
Quoted 9 lines · vibi sreenivasan
security/integrity/ima/ima_main.c +1
-1@@ -201,10 +201,10 @@ int ima_path_check(struct path *path, int mask) } out:mutex_unlock (&iint->mutex); -if (file) +if (!IS_ERR (file))fput (file);
No, IS_ERR won't catch NULL and there is 'file = NULL' on the dentry_open fail path. I still think 'if (file)' is proper condition.
What bug did you hit?
Re: [PATCH]:RESEND : Return proper error value on failure of dentry_open
Quoted 14 lines · On Mon, 01 Jun 2009 10:39:58 +0200 Jiri Slaby <[email protected]> wrote:
security/integrity/ima/ima_main.c int ima_path_check(struct path *path, int mask) · line 205
Quoted 9 lines · vibi sreenivasan
security/integrity/ima/ima_main.c +1
-1@@ -201,10 +201,10 @@ int ima_path_check(struct path *path, int mask) } out:mutex_unlock (&iint->mutex); -if (file) +if (!IS_ERR (file))fput (file);No,
IS_ERRwon't catch NULL and there is 'file = NULL' on thedentry_openfail path. I still think 'if (file)' is proper condition.
Quoted 1 line
What bug did you hit?
if (!(iint->flags & IMA_MEASURED)) {
struct dentry *dentry = dget(path->dentry);
struct vfsmount *mnt = mntget(path->mnt);
file = dentry_open(dentry, mnt, O_RDONLY | O_LARGEFILE,
current_cred());
if (IS_ERR(file)) {
pr_info("%s dentry_open failed\n", dentry->d_name.name);
rc = PTR_ERR(file);
file = NULL;
goto out;
}
rc = get_path_measurement(iint, file, dentry->d_name.name);
}
out:
mutex_unlock(&iint->mutex);
if (file)
fput(file);
kref_put(&iint->refcount, iint_free);
return 0;
}The handling of `file' looks OK to me.
otoh the function just drops the error code on the floor. Shouldn't it return `rc'?
Re: [PATCH]:RESEND : Return proper error value on failure of dentry_open
hi,
Thanks for spending your time on my patch.
Quoted 1 line
Quoted 1 line
What bug did you hit?
i was using linus tree & not linux-next.
in that the code fragment was different
it was
file = dentry_open(dentry, mnt, O_RDONLY, current->cred); rc = get_path_measurement(iint, file, dentry->d_name.name); } out: mutex_unlock(&iint->mutex); if (file) fput(file); kref_put(&iint->refcount, iint_free); return 0;
So i hit a bug in fput.
My sincere apologies for taking all of yours valuable time. I will take care that any of my future contributions will be based on linux-next.
Thanks & Regards
vibi sreenivasan
Quoted 29 lines
if (!(iint->flags & IMA_MEASURED)) { struct dentry *dentry = dget(path->dentry); struct vfsmount *mnt = mntget(path->mnt); file = dentry_open(dentry, mnt, O_RDONLY | O_LARGEFILE, current_cred()); if (IS_ERR(file)) { pr_info("%s dentry_open failed\n", dentry->d_name.name); rc = PTR_ERR(file); file = NULL; goto out; } rc = get_path_measurement(iint, file, dentry->d_name.name); } out: mutex_unlock(&iint->mutex); if (file) fput(file); kref_put(&iint->refcount, iint_free); return 0; }The handling of `file' looks OK to me.
otoh the function just drops the error code on the floor. Shouldn't it return `rc'?
Quoted 2 lines · vibi sreenivasan
dentry_opencan return error value on error.
Check that value before calling fput & return proper error value
I know you're going to redo this patch. Could you please also post with a better subject next time? :)
Jon.