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

Jan Kara
2006-08-13T21:33:29Z

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

> 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

[-- Attachment #2: quota-2.6.17-1-tty_fix.diff --]
[-- Type: text/plain, Size: 993 bytes --]

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

Signed-off-by: Jan Kara <jack@suse.cz>

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)