Re: How to lock current->signal->tty

From: Jan Kara
Date: Sun Aug 13 2006 - 17:31:35 EST


> The biggest crawly horror I've found so far in auditing the tty locking
> is current->signal->tty. The tty layer currently and explicitly protects
> this using tty_mutex. The core kernel likewise knows about this.
>
> Unfortunately:
> SELinux doesn't do any locking at all
> Dquot passes the tty to tty_write_message without locking
Ok, is something like attached patch fine?

Honza
Add proper locking when using current->signal->tty.

Signed-off-by: Jan Kara <jack@xxxxxxx>

diff -rupX /home/jack/.kerndiffexclude linux-2.6.17/fs/dquot.c linux-2.6.17-1-quota_tty_fix/fs/dquot.c
--- linux-2.6.17/fs/dquot.c 2006-08-14 09:11:29.000000000 +0200
+++ linux-2.6.17-1-quota_tty_fix/fs/dquot.c 2006-08-14 09:29:32.000000000 +0200
@@ -834,6 +834,9 @@ static void print_warning(struct dquot *
if (!need_print_warning(dquot) || (flag && test_and_set_bit(flag, &dquot->dq_flags)))
return;

+ mutex_lock(&tty_mutex);
+ if (!current->signal->tty)
+ goto out_lock;
tty_write_message(current->signal->tty, dquot->dq_sb->s_id);
if (warntype == ISOFTWARN || warntype == BSOFTWARN)
tty_write_message(current->signal->tty, ": warning, ");
@@ -861,6 +864,8 @@ static void print_warning(struct dquot *
break;
}
tty_write_message(current->signal->tty, msg);
+out_lock:
+ mutex_unlock(&tty_mutex);
}

static inline void flush_warnings(struct dquot **dquots, char *warntype)