All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] audit: fix audit_exe_compare using get_mm_exe_file
@ 2016-08-22 15:41 Richard Guy Briggs
  2016-08-22 16:27 ` Mateusz Guzik
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Guy Briggs @ 2016-08-22 15:41 UTC (permalink / raw)
  To: linux-audit, linux-kernel
  Cc: Richard Guy Briggs, mguzik, ebiederm, oleg, skinsbursky, luto,
	sgrubb, pmoore, eparis

Fix original naive attempt to get/lock access to task->mm->exe_file by
using get_mm_exe_file and checking for NULL.

See: https://lkml.org/lkml/2016/7/30/97

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
---
 kernel/audit_watch.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index d6709eb..0b29279 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <linux/file.h>
 #include <linux/kernel.h>
 #include <linux/audit.h>
 #include <linux/kthread.h>
@@ -540,14 +541,20 @@ int audit_dupe_exe(struct audit_krule *new, struct audit_krule *old)
 
 int audit_exe_compare(struct task_struct *tsk, struct audit_fsnotify_mark *mark)
 {
+	struct mm_struct *mm;
 	struct file *exe_file;
 	unsigned long ino;
 	dev_t dev;
 
-	rcu_read_lock();
-	exe_file = rcu_dereference(tsk->mm->exe_file);
+	mm = get_task_mm(tsk);
+	if (!mm)
+		return 0;
+	exe_file = get_mm_exe_file(mm);
+	mmput(mm);
+	if (!exe_file)
+		return 0;
 	ino = exe_file->f_inode->i_ino;
 	dev = exe_file->f_inode->i_sb->s_dev;
-	rcu_read_unlock();
+	fput(exe_file);
 	return audit_mark_compare(mark, ino, dev);
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] audit: fix audit_exe_compare using get_mm_exe_file
  2016-08-22 15:41 [PATCH] audit: fix audit_exe_compare using get_mm_exe_file Richard Guy Briggs
@ 2016-08-22 16:27 ` Mateusz Guzik
  0 siblings, 0 replies; 2+ messages in thread
From: Mateusz Guzik @ 2016-08-22 16:27 UTC (permalink / raw)
  To: Richard Guy Briggs
  Cc: linux-audit, linux-kernel, ebiederm, oleg, skinsbursky, luto,
	sgrubb, pmoore, eparis

On Mon, Aug 22, 2016 at 11:41:34AM -0400, Richard Guy Briggs wrote:
> Fix original naive attempt to get/lock access to task->mm->exe_file by
> using get_mm_exe_file and checking for NULL.
> 
> See: https://lkml.org/lkml/2016/7/30/97
> 
> Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
> ---
>  kernel/audit_watch.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
> index d6709eb..0b29279 100644
> --- a/kernel/audit_watch.c
> +++ b/kernel/audit_watch.c
> @@ -19,6 +19,7 @@
>   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>   */
>  
> +#include <linux/file.h>
>  #include <linux/kernel.h>
>  #include <linux/audit.h>
>  #include <linux/kthread.h>
> @@ -540,14 +541,20 @@ int audit_dupe_exe(struct audit_krule *new, struct audit_krule *old)
>  
>  int audit_exe_compare(struct task_struct *tsk, struct audit_fsnotify_mark *mark)
>  {
> +	struct mm_struct *mm;
>  	struct file *exe_file;
>  	unsigned long ino;
>  	dev_t dev;
>  
> -	rcu_read_lock();
> -	exe_file = rcu_dereference(tsk->mm->exe_file);
> +	mm = get_task_mm(tsk);
> +	if (!mm)
> +		return 0;
> +	exe_file = get_mm_exe_file(mm);
> +	mmput(mm);
> +	if (!exe_file)
> +		return 0;
>  	ino = exe_file->f_inode->i_ino;
>  	dev = exe_file->f_inode->i_sb->s_dev;
> -	rcu_read_unlock();
> +	fput(exe_file);
>  	return audit_mark_compare(mark, ino, dev);
>  }

I think this works but I have a better idea. This basically duplicates a
part of proc_exe_link and does unnecessary work.

Instead, one can introduce get_task_exe_file. task_lock held guarantees
the stability of mm struct itself, and then we can we can try to grab
the file without mm refcount dance.

I'll implement this later today.

-- 
Mateusz Guzik

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-22 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 15:41 [PATCH] audit: fix audit_exe_compare using get_mm_exe_file Richard Guy Briggs
2016-08-22 16:27 ` Mateusz Guzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.