Skip to contentSkip to conversation

2.3.31++: Badness at kernel/softirq.c:143 due to new session leader connector

PATCH In review Christian Borntraeger 5 participants 21 messages Sep 25, 2009 – Oct 14, 2009 1 message not in the archive

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

Scott,

I am using the proc connector for fork and exit tracking. With the latest git the new session leader connector(commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 proc connector: add event for process becoming session leader) causes the following warning:

------------[ cut here ]------------
Badness at kernel/softirq.c:143
Modules linked in: tun bridge stp kvm sclp_cpi dm_multipath scsi_dh sunrpc ipv6 
qeth_l2 binfmt_misc dm_mod qeth ccwgroup
CPU: 7 Not tainted 2.6.31-selfgit-08936-g851b147-dirty #130
Process xzd (pid: 7189, task: 000000013d804758, ksp: 00000001329eddb8)
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0)
           R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 EA:3
Krnl GPRS: 0000000000000000 0000000000fcdd68 0000000100000000 00000001329ee000
           00000000008268a8 0000000132980bb4 0000000000000000 0000000132980ac8
           0000000000000001 0000000132980ac8 0000000100000000 000000013db3a470
           0000000132980ac8 0000000000525de8 000000000048a946 00000001329edc58
Krnl Code: 00000000001481c6: e33002f00004       lg      %r3,752
           00000000001481cc: a7f4ffd8           brc     15,14817c
           00000000001481d0: a7f40001           brc     15,1481d2
          >00000000001481d4: a7280001           lhi     %r2,1
           00000000001481d8: 50201000           st      %r2,0(%r1)
           00000000001481dc: a7f4ffd0           brc     15,14817c
           00000000001481e0: c0e5fffe4b76       brasl   %r14,1118cc
           00000000001481e6: e33002f00004       lg      %r3,752
Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

Last Breaking-Event-Address:
[<00000000001481d0>] local_bh_enable+0xac/0xe0

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

I think the problem is, that sys_setsid holds the tasklist_lock with spinlock_irq. while calling the connector.

Any ideas for a proper fix?

Christian

#1 lore raw

Resending, since the problem does still exist.

Am Freitag 25 September 2009 11:23:03 schrieb Christian Borntraeger:

Quoted 61 lines

Scott,

I am using the proc connector for fork and exit tracking. With the latest
git the new session leader connector(commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 proc connector: add event for process becoming session leader)
causes the following warning:

------------[ cut here ]------------
Badness at kernel/softirq.c:143
Modules linked in: tun bridge stp kvm sclp_cpi dm_multipath scsi_dh sunrpc
 ipv6 qeth_l2 binfmt_misc dm_mod qeth ccwgroup
CPU: 7 Not tainted 2.6.31-selfgit-08936-g851b147-dirty #130
Process xzd (pid: 7189, task: 000000013d804758, ksp: 00000001329eddb8)
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0)
           R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 EA:3

Krnl GPRS: 0000000000000000 0000000000fcdd68 0000000100000000
00000001329ee000 00000000008268a8 0000000132980bb4 0000000000000000 0000000132980ac8 0000000000000001 0000000132980ac8 0000000100000000 000000013db3a470 0000000132980ac8 0000000000525de8 000000000048a946
00000001329edc58 Krnl Code: 00000000001481c6: e33002f00004 lg
%r3,752

           00000000001481cc: a7f4ffd8           brc     15,14817c
           00000000001481d0: a7f40001           brc     15,1481d2
          >00000000001481d4: a7280001           lhi     %r2,1

           00000000001481d8: 50201000           st      %r2,0(%r1)
           00000000001481dc: a7f4ffd0           brc     15,14817c
           00000000001481e0: c0e5fffe4b76       brasl   %r14,1118cc
           00000000001481e6: e33002f00004       lg      %r3,752
Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

Last Breaking-Event-Address:
[<00000000001481d0>] local_bh_enable+0xac/0xe0

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

I think the problem is, that sys_setsid holds the tasklist_lock with spinlock_irq. while calling the connector.

Any ideas for a proper fix?

Christian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 5 lines · Evgeny Polyakov

I'm yet do download the latest git to check this particular patch, but I suppose it is possible to copy data under the lock into temporary buffer and then send it using existing infrastructure instead of calling it under the tasklist lock.

Afaics, we can just shift proc_sid_connector() from __set_special_pids() to sys_setsid().

Oleg.

#4 lore raw

PATCH 1/1 connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Am Dienstag 29 September 2009 15:24:15 schrieb Oleg Nesterov:

Quoted 8 lines · Evgeny Polyakov
Quoted 4 lines

I'm yet do download the latest git to check this particular patch, but I suppose it is possible to copy data under the lock into temporary buffer and then send it using existing infrastructure instead of calling it under the tasklist lock.

Afaics, we can just shift proc_sid_connector() from __set_special_pids() to sys_setsid().

Ok, can confirm that this patch fixes my problem, but I am not sure if the intended behaviour is still working as expected.

[PATCH] connector: Fix sid connector

The sid connector gives the following warning:
Badness at kernel/softirq.c:143
[...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector. We can safely move proc_sid_connector from __set_special_pids to sys_setsid.

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +1 -3
Index: linux-2.6/kernel/exit.c
===================================================================
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c +2 -0
Index: linux-2.6/kernel/sys.c
===================================================================
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (!err)
+		proc_sid_connector(sid);
 	return err;
 }
 
#5 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1114

Quoted 9 lines · Christian Borntraeger
kernel/sys.c +2 -0
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (!err)
+		proc_sid_connector(sid);

sys_setsid() returns the session nr on success, not zero.

	if (err > 0)
		proc_sid_connector(sid);

Otherwize I think the patch is fine. Not only it should fix the problem, imho it makes the code cleaner.

If Scott still thinks daemonize() should report too, we can change it.

(I'd suggest you to CC Andrew if you are going to re-send)

Oleg.

#6 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

In reply to Christian Borntraeger
Quoted 2 lines · Christian Borntraeger

Ok, can confirm that this patch fixes my problem, but I am not sure if the intended behaviour is still working as expected.

Your patch breaks assumption that task_session(current->group_leader) is not equal to new session id, but to check task_session() we need either rcu or task lock. Also setsid() return value is not zero or negative error, but new session ID or negative error, so I believe attached patch is a proper fix, although it looks rather ugly.

Also proc_sid_connector() uses GFP_KERNEL allocation which is way too wrong to use under any locks.

Something like this (not tested :)

kernel/exit.c +1 -3
index 5859f59..1565baf 100644
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c +7 -0
index 255475d..b852a8b 100644
@@ -1090,6 +1090,7 @@ SYSCALL_DEFINE0(setsid)
 	struct pid *sid = task_pid(group_leader);
 	pid_t session = pid_vnr(sid);
 	int err = -EPERM;
+	int send_cn = 0;
 
 	write_lock_irq(&tasklist_lock);
 	/* Fail if I am already a session leader */
@@ -1104,12 +1105,18 @@ SYSCALL_DEFINE0(setsid)
 
 	group_leader->signal->leader = 1;
 	__set_special_pids(sid);
+	if (task_session(group_leader) != sid)
+		send_cn = 1;
 
 	proc_clear_tty(group_leader);
 
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+
+	if (send_cn)
+		proc_sid_connector(group_leader);
+
 	return err;
 }
 
Signature · 1 line
	Evgeniy Polyakov
#7 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Am Dienstag 29 September 2009 16:07:18 schrieb Evgeniy Polyakov:

Quoted 4 lines

Your patch breaks assumption that task_session(current->group_leader) is not equal to new session id, but to check task_session() we need either rcu or task lock. Also setsid() return value is not zero or negative error, but new session ID or negative error,

Right.

Quoted 6 lines

so I believe attached patch is a proper fix, although it looks rather ugly.

Also proc_sid_connector() uses GFP_KERNEL allocation which is way too wrong to use under any locks.

Something like this (not tested :)

Patch compiles and seems to work.

Christian

#8 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

In reply to Evgeniy Polyakov
Quoted 7 lines · Evgeniy Polyakov
Quoted 2 lines · Christian Borntraeger

Ok, can confirm that this patch fixes my problem, but I am not sure if the intended behaviour is still working as expected.

Your patch breaks assumption that task_session(current->group_leader) is not equal to new session id,

Afaics, no.

Quoted 11 lines
kernel/sys.c +1 -0
@@ -1090,6 +1090,7 @@ SYSCALL_DEFINE0(setsid)
 	struct pid *sid = task_pid(group_leader);
 	pid_t session = pid_vnr(sid);
 	int err = -EPERM;
+	int send_cn = 0;
 
 	write_lock_irq(&tasklist_lock);
 	/* Fail if I am already a session leader */

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1109

Quoted 5 lines
kernel/sys.c +2 -0
@@ -1104,12 +1105,18 @@ SYSCALL_DEFINE0(setsid)
 
 	group_leader->signal->leader = 1;
 	__set_special_pids(sid);
+	if (task_session(group_leader) != sid)
+		send_cn = 1;

This is not right, task_session(group_leader) must be == sid after __set_special_pids().

And I don't think "int send_cn" is needed. sys_setsid() must not succeed if the caller lived in session == task_pid(group_leader).

Or I missed your point?

Oleg.

#9 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Quoted 32 lines · Oleg Nesterov
Quoted 7 lines · Evgeniy Polyakov
Quoted 2 lines · Christian Borntraeger

Ok, can confirm that this patch fixes my problem, but I am not sure if the intended behaviour is still working as expected.

Your patch breaks assumption that task_session(current->group_leader) is not equal to new session id,

Afaics, no.

Quoted 11 lines
kernel/sys.c +1 -0
@@ -1090,6 +1090,7 @@ SYSCALL_DEFINE0(setsid)
 	struct pid *sid = task_pid(group_leader);
 	pid_t session = pid_vnr(sid);
 	int err = -EPERM;
+	int send_cn = 0;
 
 	write_lock_irq(&tasklist_lock);
 	/* Fail if I am already a session leader */

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1109

Quoted 5 lines
kernel/sys.c +2 -0
@@ -1104,12 +1105,18 @@ SYSCALL_DEFINE0(setsid)
 
 	group_leader->signal->leader = 1;
 	__set_special_pids(sid);
+	if (task_session(group_leader) != sid)
+		send_cn = 1;

This is not right, task_session(group_leader) must be == sid after __set_special_pids().

Quoted 2 lines

And I don't think "int send_cn" is needed. sys_setsid() must not succeed if the caller lived in session == task_pid(group_leader).

IOW, if sys_setsid() succeeds, we know it creates the new unique session, we should report this change.

Note this check

	if (pid_task(sid, PIDTYPE_PGID))
		goto out;

before we actually change pids.

I think Christian's patch only needs the small fixup.

Oleg.

#10 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Am Dienstag 29 September 2009 16:45:54 schrieb Oleg Nesterov:

Quoted 1 line

I think Christian's patch only needs the small fixup.

Oleg, Evgeniy,

just in case the discussion concludes that my patch is fine, here is a fixed version.

[PATCH] connector: Fix sid connector

The sid connector gives the following warning:
Badness at kernel/softirq.c:143
[...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector. We can safely move proc_sid_connector from __set_special_pids to sys_setsid.

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +1 -3
Index: linux-2.6/kernel/exit.c
===================================================================
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c +2 -0
Index: linux-2.6/kernel/sys.c
===================================================================
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(sid);
 	return err;
 }
 
Acked-by
#11 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Quoted 35 lines · Christian Borntraeger

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector. We can safely move proc_sid_connector from __set_special_pids to sys_setsid.

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)

Index: linux-2.6/kernel/exit.c
===================================================================

kernel/exit.c +1 -3
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);

Index: linux-2.6/kernel/sys.c
===================================================================

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1116

Quoted 7 lines
kernel/sys.c +2 -0
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(sid);
 	return err;
 }

I'd suggest you to resend this patch to Andrew. Unless you know another way to push it into Linus's tree ;)

Perhaps it makes sense to update the changelog, it should mention the issues with daemonize().

Oleg.

#12 lore raw

PATCH 1/1 connector: Fix regression introduced by sid connector

Hi Andrew,

since commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 (proc connector: add event for process becoming session leader) we have the following warning:
Badness at kernel/softirq.c:143
[...]
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0) [...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector.
After a discussion we agreed that we can move proc_sid_connector from __set_special_pids to sys_setsid.
We also agreed that it is sufficient to change the check from task_session(curr) != pid into err > 0, since if we don't change the session, this means we were already the leader and return -EPERM.

One last thing:
There is also daemonize(), and some people might want to get a notification in that case. Since daemonize() is only needed if a user space does kernel_thread this does not look important (and there seems to be no consensus if this connector should be called in daemonize). If we really want this, we can add proc_sid_connector to daemonize() in an additional patch (Scott?)

CCed: Scott James Remnant <[email protected]>
CCed: Matt Helsley <[email protected]>
CCed: David S. Miller <[email protected]>

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +1 -3
Index: linux-2.6/kernel/exit.c
===================================================================
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c +2 -0
Index: linux-2.6/kernel/sys.c
===================================================================
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(sid);
 	return err;
 }
 
#13 lore raw

Re: [PATCH] connector: Fix regression introduced by sid connector

Quoted 71 lines · On Wed, 30 Sep 2009 08:43:11 +0200 Christian Borntraeger…

Hi Andrew,

since commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 (proc connector: add event for process becoming session leader) we have the following warning:
Badness at kernel/softirq.c:143
[...]
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0) [...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector.
After a discussion we agreed that we can move proc_sid_connector from __set_special_pids to sys_setsid.
We also agreed that it is sufficient to change the check from task_session(curr) != pid into err > 0, since if we don't change the session, this means we were already the leader and return -EPERM.

One last thing:
There is also daemonize(), and some people might want to get a notification in that case. Since daemonize() is only needed if a user space does kernel_thread this does not look important (and there seems to be no consensus if this connector should be called in daemonize). If we really want this, we can add proc_sid_connector to daemonize() in an additional patch (Scott?)

CCed: Scott James Remnant <[email protected]>
CCed: Matt Helsley <[email protected]>
CCed: David S. Miller <[email protected]>

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)

Index: linux-2.6/kernel/exit.c
===================================================================

kernel/exit.c +1 -3
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);

Index: linux-2.6/kernel/sys.c
===================================================================

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1116

Quoted 7 lines
kernel/sys.c +2 -0
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(sid);
 	return err;
 }

kernel/sys.c: In function 'sys_setsid':
kernel/sys.c:1114: warning: passing argument 1 of 'proc_sid_connector' from incompatible pointer type

Pass a struct pid*' into a function expecting a struct task_struct*'. Surely it will crash??

Please redo the patch and test it more carefully.

#14 lore raw

Re: [PATCH] connector: Fix regression introduced by sid connector

Quoted 18 lines · Andrew Morton

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1116

Quoted 10 lines · On Wed, 30 Sep 2009 08:43:11 +0200 Christian Borntraeger…
kernel/sys.c +2 -0
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(sid);
 	return err;
 }

kernel/sys.c: In function 'sys_setsid':
kernel/sys.c:1114: warning: passing argument 1 of 'proc_sid_connector' from incompatible pointer type

Quoted 2 lines

Pass a struct pid*' into a function expecting a struct task_struct*'. Surely it will crash??

Oh, indeed, it should be

	proc_sid_connector(group_leader);

Oleg.

author Acked-by Oleg Nesterov Acked-by Evgeniy Polyakov
#15 lore raw

Re: [PATCH] connector: Fix regression introduced by sid connector

In reply to Andrew Morton

Sorry about that. Dont know how this escaped. It was probably hiding between all the sparse warnings I get in kernel/* and a lack of knowledge in this area.
Here is a new version:

since commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 (proc connector: add event for process becoming session leader) we have the following warning:
Badness at kernel/softirq.c:143
[...]
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0) [...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector.
After a discussion we agreed that we can move proc_sid_connector from __set_special_pids to sys_setsid.
We also agreed that it is sufficient to change the check from task_session(curr) != pid into err > 0, since if we don't change the session, this means we were already the leader and return -EPERM.

One last thing:
There is also daemonize(), and some people might want to get a notification in that case. Since daemonize() is only needed if a user space does kernel_thread this does not look important (and there seems to be no consensus if this connector should be called in daemonize). If we really want this, we can add proc_sid_connector to daemonize() in an additional patch (Scott?)

CCed: Scott James Remnant <[email protected]>
CCed: Matt Helsley <[email protected]>
CCed: David S. Miller <[email protected]>

---
 kernel/exit.c |    4 +---
 kernel/sys.c  |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +1 -3
Index: linux-2.6/kernel/exit.c
===================================================================
@@ -359,10 +359,8 @@ void __set_special_pids(struct pid *pid)
 {
 	struct task_struct *curr = current->group_leader;
 
-	if (task_session(curr) != pid) {
+	if (task_session(curr) != pid)
 		change_pid(curr, PIDTYPE_SID, pid);
-		proc_sid_connector(curr);
-	}
 
 	if (task_pgrp(curr) != pid)
 		change_pid(curr, PIDTYPE_PGID, pid);
kernel/sys.c +2 -0
Index: linux-2.6/kernel/sys.c
===================================================================
@@ -1110,6 +1110,8 @@ SYSCALL_DEFINE0(setsid)
 	err = session;
 out:
 	write_unlock_irq(&tasklist_lock);
+	if (err > 0)
+		proc_sid_connector(group_leader);
 	return err;
 }
 
#16 lore raw

Re: [PATCH] connector: Fix regression introduced by sid connector

Quoted 37 lines · Christian Borntraeger

since commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 (proc connector: add event for process becoming session leader) we have the following warning:
Badness at kernel/softirq.c:143
[...]
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0) [...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector.
After a discussion we agreed that we can move proc_sid_connector from __set_special_pids to sys_setsid.
We also agreed that it is sufficient to change the check from task_session(curr) != pid into err > 0, since if we don't change the session, this means we were already the leader and return -EPERM.

One last thing:
There is also daemonize(), and some people might want to get a notification in that case. Since daemonize() is only needed if a user space does kernel_thread this does not look important (and there seems to be no consensus if this connector should be called in daemonize). If we really want this, we can add proc_sid_connector to daemonize() in an additional patch (Scott?)

Quoted 6 lines

CCed: Scott James Remnant <[email protected]>
CCed: Matt Helsley <[email protected]>
CCed: David S. Miller <[email protected]>

I was getting the same softirq warnings and later in slub in slab_alloc() at might_sleep_if(gfpflags & __GFP_WAIT) from __alloc_skb(..., GFP_KERNEL) in this context that would infinitely spam my log.

#17 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

In reply to Christian Borntraeger
Quoted 22 lines · Christian Borntraeger

just in case the discussion concludes that my patch is fine, here is a fixed version.

[PATCH] connector: Fix sid connector

The sid connector gives the following warning:
Badness at kernel/softirq.c:143
[...]

Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

Quoted 6 lines

The network code must not be called with disabled interrupts but sys_setsid holds the tasklist_lock with spinlock_irq while calling the connector. We can safely move proc_sid_connector from __set_special_pids to sys_setsid.

Looks good, thank you.
Ack.

Signature · 1 line
	Evgeniy Polyakov
#18 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

In reply to Oleg Nesterov
Quoted 12 lines · Oleg Nesterov
Quoted 12 lines
kernel/sys.c +1 -0
@@ -1090,6 +1090,7 @@ SYSCALL_DEFINE0(setsid)
 	struct pid *sid = task_pid(group_leader);
 	pid_t session = pid_vnr(sid);
 	int err = -EPERM;
+	int send_cn = 0;
 
 	write_lock_irq(&tasklist_lock);
 	/* Fail if I am already a session leader */
@@ -1104,12 +1105,18 @@ SYSCALL_DEFINE0(setsid)
 
Quoted 7 lines

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1109

Quoted 4 lines
kernel/sys.c +2 -0
 	group_leader->signal->leader = 1;
 	__set_special_pids(sid);
+	if (task_session(group_leader) != sid)
+		send_cn = 1;

This is not right, task_session(group_leader) must be == sid after __set_special_pids().

Yeah, that check should be done before __set_special_pids().

Quoted 2 lines

And I don't think "int send_cn" is needed. sys_setsid() must not succeed if the caller lived in session == task_pid(group_leader).

Doesn't it only check pgid while patch intention was to send notification about sid? I.e. setsid() succeeds, although nothing happens.

Signature · 1 line
	Evgeniy Polyakov
#19 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Quoted 22 lines · Evgeniy Polyakov
Quoted 12 lines · Oleg Nesterov
Quoted 12 lines
kernel/sys.c +1 -0
@@ -1090,6 +1090,7 @@ SYSCALL_DEFINE0(setsid)
 	struct pid *sid = task_pid(group_leader);
 	pid_t session = pid_vnr(sid);
 	int err = -EPERM;
+	int send_cn = 0;
 
 	write_lock_irq(&tasklist_lock);
 	/* Fail if I am already a session leader */
@@ -1104,12 +1105,18 @@ SYSCALL_DEFINE0(setsid)
 
Quoted 7 lines

kernel/sys.c SYSCALL_DEFINE0(setsid) · line 1109

Quoted 4 lines
kernel/sys.c +2 -0
 	group_leader->signal->leader = 1;
 	__set_special_pids(sid);
+	if (task_session(group_leader) != sid)
+		send_cn = 1;

This is not right, task_session(group_leader) must be == sid after __set_special_pids().

Quoted 7 lines

Yeah, that check should be done before __set_special_pids().

Quoted 2 lines

And I don't think "int send_cn" is needed. sys_setsid() must not succeed if the caller lived in session == task_pid(group_leader).

Doesn't it only check pgid while patch intention was to send notification about sid?

If the proposed sid already was the session id, then prgp shouldn't be empty.

but this doesn't really matter, we also check ->signal->leader (not sure, but afaics this check is not strictly necessary because
of PIDTYPE_PGID check)

Quoted 2 lines

I.e. setsid() succeeds, although nothing
happens.

This shouldn't happen, or sys_setsid() is buggy. Look, the new session id is task_pid(current). If sys_setsid() succeeds but we don't change the session, this means we were already the leader. In that case we should return -EPERM.

Oleg.

#20 lore raw

Re: [PATCH] connector: Fix sid connector (was: Badness at kernel/softirq.c:143...)

Quoted 9 lines · Oleg Nesterov
Quoted 2 lines

Doesn't it only check pgid while patch intention was to send notification about sid?

If the proposed sid already was the session id, then prgp shouldn't be empty.

but this doesn't really matter, we also check ->signal->leader (not sure, but afaics this check is not strictly necessary because
of PIDTYPE_PGID check)

Ok, I see, thanks.

Signature · 1 line
	Evgeniy Polyakov
#21 lore raw
In reply to Christian Borntraeger
Quoted 40 lines · Christian Borntraeger

I am using the proc connector for fork and exit tracking. With the latest git the new session leader connector(commit 02b51df1b07b4e9ca823c89284e704cadb323cd1 proc connector: add event for process becoming session leader) causes the following warning:

------------[ cut here ]------------
Badness at kernel/softirq.c:143
Modules linked in: tun bridge stp kvm sclp_cpi dm_multipath scsi_dh sunrpc ipv6 
qeth_l2 binfmt_misc dm_mod qeth ccwgroup
CPU: 7 Not tainted 2.6.31-selfgit-08936-g851b147-dirty #130
Process xzd (pid: 7189, task: 000000013d804758, ksp: 00000001329eddb8)
Krnl PSW : 0404c00180000000 00000000001481d4 (local_bh_enable+0xb0/0xe0)
           R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 EA:3
Krnl GPRS: 0000000000000000 0000000000fcdd68 0000000100000000 00000001329ee000
           00000000008268a8 0000000132980bb4 0000000000000000 0000000132980ac8
           0000000000000001 0000000132980ac8 0000000100000000 000000013db3a470
           0000000132980ac8 0000000000525de8 000000000048a946 00000001329edc58
Krnl Code: 00000000001481c6: e33002f00004       lg      %r3,752
           00000000001481cc: a7f4ffd8           brc     15,14817c
           00000000001481d0: a7f40001           brc     15,1481d2
          >00000000001481d4: a7280001           lhi     %r2,1
           00000000001481d8: 50201000           st      %r2,0(%r1)
           00000000001481dc: a7f4ffd0           brc     15,14817c
           00000000001481e0: c0e5fffe4b76       brasl   %r14,1118cc
           00000000001481e6: e33002f00004       lg      %r3,752
Call Trace:
([<000000013fe04100>] 0x13fe04100)
 [<000000000048a946>] sk_filter+0x9a/0xd0
 [<000000000049d938>] netlink_broadcast+0x2c0/0x53c
 [<00000000003ba9ae>] cn_netlink_send+0x272/0x2b0
 [<00000000003baef0>] proc_sid_connector+0xc4/0xd4
 [<0000000000142604>] __set_special_pids+0x58/0x90
 [<0000000000159938>] sys_setsid+0xb4/0xd8
 [<00000000001187fe>] sysc_noemu+0x10/0x16
 [<00000041616cb266>] 0x41616cb266

Last Breaking-Event-Address:
[<00000000001481d0>] local_bh_enable+0xac/0xe0

Quoted 5 lines

The warning is
---> WARN_ON_ONCE(in_irq() || irqs_disabled());

I think the problem is, that sys_setsid holds the tasklist_lock with spinlock_irq. while calling the connector.

Yes, local_bh_enable() doesn't like irqs_disabled().

Quoted 1 line

Any ideas for a proper fix?

Please see http://lkml.org/lkml/2009/6/23/690

As for daemonize(), I don't think this case is important. Even if it is, we can add proc_sid_connector() to daemonize() as well.

Oleg.