Skip to content

Commit bde02ca

Browse files
committed
audit: use spin_lock_irqsave/restore in audit tty code
Some of the callers of the audit tty function use spin_lock_irqsave/restore. We were using the forced always enable version, which seems really bad. Since I don't know every one of these code paths well enough, it makes sense to just switch everything to the safe version. Maybe it's a little overzealous, but it's a lot better than an unlucky deadlock when we return to a caller with irq enabled and they expect it to be disabled. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 4d3fb70 commit bde02ca

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎drivers/tty/tty_audit.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ static void tty_audit_buf_push(struct tty_audit_buf *buf)
111111
void tty_audit_exit(void)
112112
{
113113
struct tty_audit_buf *buf;
114+
unsigned long flags;
114115

115-
spin_lock_irq(&current->sighand->siglock);
116+
spin_lock_irqsave(&current->sighand->siglock, flags);
116117
buf = current->signal->tty_audit_buf;
117118
current->signal->tty_audit_buf = NULL;
118-
spin_unlock_irq(&current->sighand->siglock);
119+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
119120
if (!buf)
120121
return;
121122

@@ -133,9 +134,11 @@ void tty_audit_exit(void)
133134
*/
134135
void tty_audit_fork(struct signal_struct *sig)
135136
{
136-
spin_lock_irq(&current->sighand->siglock);
137+
unsigned long flags;
138+
139+
spin_lock_irqsave(&current->sighand->siglock, flags);
137140
sig->audit_tty = current->signal->audit_tty;
138-
spin_unlock_irq(&current->sighand->siglock);
141+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
139142
}
140143

141144
/**
@@ -145,13 +148,14 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
145148
{
146149
struct tty_audit_buf *buf;
147150
int major, minor, should_audit;
151+
unsigned long flags;
148152

149-
spin_lock_irq(&current->sighand->siglock);
153+
spin_lock_irqsave(&current->sighand->siglock, flags);
150154
should_audit = current->signal->audit_tty;
151155
buf = current->signal->tty_audit_buf;
152156
if (buf)
153157
atomic_inc(&buf->count);
154-
spin_unlock_irq(&current->sighand->siglock);
158+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
155159

156160
major = tty->driver->major;
157161
minor = tty->driver->minor_start + tty->index;
@@ -221,18 +225,19 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
221225
unsigned icanon)
222226
{
223227
struct tty_audit_buf *buf, *buf2;
228+
unsigned long flags;
224229

225230
buf = NULL;
226231
buf2 = NULL;
227-
spin_lock_irq(&current->sighand->siglock);
232+
spin_lock_irqsave(&current->sighand->siglock, flags);
228233
if (likely(!current->signal->audit_tty))
229234
goto out;
230235
buf = current->signal->tty_audit_buf;
231236
if (buf) {
232237
atomic_inc(&buf->count);
233238
goto out;
234239
}
235-
spin_unlock_irq(&current->sighand->siglock);
240+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
236241

237242
buf2 = tty_audit_buf_alloc(tty->driver->major,
238243
tty->driver->minor_start + tty->index,
@@ -242,7 +247,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
242247
return NULL;
243248
}
244249

245-
spin_lock_irq(&current->sighand->siglock);
250+
spin_lock_irqsave(&current->sighand->siglock, flags);
246251
if (!current->signal->audit_tty)
247252
goto out;
248253
buf = current->signal->tty_audit_buf;
@@ -254,7 +259,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
254259
atomic_inc(&buf->count);
255260
/* Fall through */
256261
out:
257-
spin_unlock_irq(&current->sighand->siglock);
262+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
258263
if (buf2)
259264
tty_audit_buf_free(buf2);
260265
return buf;
@@ -317,16 +322,17 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
317322
void tty_audit_push(struct tty_struct *tty)
318323
{
319324
struct tty_audit_buf *buf;
325+
unsigned long flags;
320326

321-
spin_lock_irq(&current->sighand->siglock);
327+
spin_lock_irqsave(&current->sighand->siglock, flags);
322328
if (likely(!current->signal->audit_tty)) {
323-
spin_unlock_irq(&current->sighand->siglock);
329+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
324330
return;
325331
}
326332
buf = current->signal->tty_audit_buf;
327333
if (buf)
328334
atomic_inc(&buf->count);
329-
spin_unlock_irq(&current->sighand->siglock);
335+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
330336

331337
if (buf) {
332338
int major, minor;

‎kernel/audit.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,11 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
804804
case AUDIT_TTY_GET: {
805805
struct audit_tty_status s;
806806
struct task_struct *tsk = current;
807+
unsigned long flags;
807808

808-
spin_lock_irq(&tsk->sighand->siglock);
809+
spin_lock_irqsave(&tsk->sighand->siglock, flags);
809810
s.enabled = tsk->signal->audit_tty != 0;
810-
spin_unlock_irq(&tsk->sighand->siglock);
811+
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
811812

812813
audit_send_reply(NETLINK_CB(skb).portid, seq,
813814
AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
@@ -816,16 +817,17 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
816817
case AUDIT_TTY_SET: {
817818
struct audit_tty_status *s;
818819
struct task_struct *tsk = current;
820+
unsigned long flags;
819821

820822
if (nlh->nlmsg_len < sizeof(struct audit_tty_status))
821823
return -EINVAL;
822824
s = data;
823825
if (s->enabled != 0 && s->enabled != 1)
824826
return -EINVAL;
825827

826-
spin_lock_irq(&tsk->sighand->siglock);
828+
spin_lock_irqsave(&tsk->sighand->siglock, flags);
827829
tsk->signal->audit_tty = s->enabled != 0;
828-
spin_unlock_irq(&tsk->sighand->siglock);
830+
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
829831
break;
830832
}
831833
default:

0 commit comments

Comments
 (0)