Skip to contentSkip to conversation

file: Add locking to f_getown

PATCH New Eric W. Biederman 1 participant 1 message Sep 10, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 file: Add locking to f_getown

This has been needed for a long time, but now with the advent of a reference counted struct pid there are real consequences for getting this wrong.

Someone I think it was Oleg Nesterov pointed out that this construct was missing locking, when I introduced struct pid. After taking time to review the locking construct already present I figured out which lock needs to be taken. The other paths that access f_owner.pid take either the f_owner read or the write lock.

---
 fs/fcntl.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
fs/fcntl.c +2 -0
index 821ebb9..b1dd4d4 100644
@@ -305,9 +305,11 @@ void f_delown(struct file *filp)
 pid_t f_getown(struct file *filp)
 {
 	pid_t pid;
+	read_lock(&filp->f_owner.lock);
 	pid = pid_nr(filp->f_owner.pid);
 	if (filp->f_owner.pid_type == PIDTYPE_PGID)
 		pid = -pid;
+	read_unlock(&filp->f_owner.lock);
 	return pid;
 }
 
Signature · 1 line
1.4.2.rc3.g7e18e-dirty