[PATCH] removed socket buffer in unix domain socket

Yasuma Takeda (yasuma@miraclelinux.com)
Mon, 7 Jan 2002 17:39:44 +0900


This is a multi-part message in MIME format.

--Multipart_Mon__7_Jan_2002_17:39:44_+0900_083e6930
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hi,

I found a problem to unix domain socket.

The unix_gc function removes socket buffers of the socket
which is connectted but not acceptted yet.

After one process executes "Mark phase" of unix_gc function,
another process registers socket buffer by using sendmsg with SCM_RIGHTS.
At the next moment, the socket buffer is removed.

I attached the test program.
When I execute one server and two clients on SMP machine
(kernel 2.4.16 and PentiumIII x 2), I can reporduce this problem.

Following is a patch to avoid this problem.

--- kernel-2.4.16/net/unix/garbage.c.sv Mon Jan 7 15:46:22 2002
+++ kernel-2.4.16/net/unix/garbage.c Mon Jan 7 15:51:22 2002
@@ -279,7 +279,7 @@
/*
* Do we have file descriptors ?
*/
- if(UNIXCB(skb).fp)
+ if(s->dead && UNIXCB(skb).fp)
{
__skb_unlink(skb, skb->list);
__skb_queue_tail(&hitlist,skb);

Regards,

Yasuma Takeda

--Multipart_Mon__7_Jan_2002_17:39:44_+0900_083e6930
Content-Type: text/x-csrc;
name="client.c"
Content-Disposition: attachment;
filename="client.c"
Content-Transfer-Encoding: base64

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNpbmNsdWRlIDxzeXMv
dGltZS5oPgojaW5jbHVkZSA8c3lzL3R5cGVzLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNp
bmNsdWRlIDxzeXMvZmNudGwuaD4KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4KI2luY2x1ZGUgPHN5
cy91aW8uaD4KI2luY2x1ZGUgPHN5cy91bi5oPgojaW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRl
IDxlcnJuby5oPgoKbWFpbihpbnQgYXJnYyxjaGFyICoqIGFyZ3YpCnsKCglzdHJ1Y3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CQkJZXhpdCgtMSk7CgkJfQoJCWZw
cmludGYoc3RkZXJyLCAiWyVkXTpzZW5kbXNnKCkgJWQgYnl0ZSBPSy4gZmQ6JWRcbiIsIG4sIHJl
dCwgZmRbMF0pOwoJCQoJCXZlYy5pb3ZfYmFzZSA9IHJlcGx5OwoJCXZlYy5pb3ZfbGVuICA9IDEy
ODsKCQkKCQltc2doZHIubXNnX25hbWUgICAgICAgPSBOVUxMOwoJCW1zZ2hkci5tc2dfbmFtZWxl
biAgICA9IDA7CgkJbXNnaGRyLm1zZ19pb3YgICAgICAgID0gJnZlYzsKCQltc2doZHIubXNnX2lv
dmxlbiAgICAgPSAxOwoJCW1zZ2hkci5tc2dfZmxhZ3MgPSAwOwoJCW1zZ2hkci5tc2dfY29udHJv
bGxlbiA9IDA7CgkJbXNnaGRyLm1zZ19jb250cm9sICAgID0gTlVMTDsKCQkKCQlpZiAoKHJldCA9
IHJlY3Ztc2cocywgJm1zZ2hkciwgMCkpIDwgMTI4KSB7CgkJCWZwcmludGYoc3RkZXJyLCAicmVj
dm1zZygpIGVycm9yICVkXG4iLCBlcnJubyk7CgkJCWV4aXQoLTEpOwoJCX0KCQlmcHJpbnRmKHN0
ZGVyciwgInJlY3ZtZ3MoKSAlZCBieXRlIE9LLlxuIiwgcmV0KTsKCgkJY2xvc2Uocyk7CgkJbisr
OwoJfQoJCglmcHJpbnRmKHN0ZGVyciwiR09PRCBCWSBcbiIpOwoJZXhpdCAoMCk7Cn0KCgoKCg==

--Multipart_Mon__7_Jan_2002_17:39:44_+0900_083e6930
Content-Type: text/x-csrc;
name="server.c"
Content-Disposition: attachment;
filename="server.c"
Content-Transfer-Encoding: base64

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNpbmNsdWRlIDxzeXMv
dGltZS5oPgojaW5jbHVkZSA8c3lzL3R5cGVzLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNp
bmNsdWRlID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WYgKGNtc2ctPmNtc2df
bGV2ZWwgPT0gU09MX1NPQ0tFVCkgewoJCQkJCQlwYXNzX2ZkX3B0ciA9IChpbnQgKilDTVNHX0RB
VEEoY21zZyk7CgkJCQkJCWJyZWFrOwoJCQkJCX0KCQkJCX0KCQkJCWZwcmludGYoc3Rkb3V0LCAi
cmVjdm1zZygpIGlzIGRvbmUuXG4iKTsKCQkJCWNsb3NlKCpwYXNzX2ZkX3B0cik7CgoJCQkJbXNn
aGRyLm1zZ19uYW1lICAgID0gTlVMTDsKCQkJCW1zZ2hkci5tc2dfbmFtZWxlbiA9IDA7CgkJCQlt
c2doZHIubXNnX2lvdiAgICAgPSAmdmVjOwoJCQkJbXNnaGRyLm1zZ19pb3ZsZW4gID0gMTsKCQkJ
CW1zZ2hkci5tc2dfY29udHJvbGxlbiA9IDA7CgkJCQltc2doZHIubXNnX2NvbnRyb2wgICAgPSBO
VUxMOwoJCQkJdmVjLmlvdl9iYXNlICA9IHJlcGx5OwoJCQkJdmVjLmlvdl9sZW4gICA9IDEyODsK
CQkJCWlmICgocmV0ID0gc2VuZG1zZyhjbGllbnRfZmQsICZtc2doZHIsIDAgKSkgPCAxMjgpIHsK
CQkJCQlmcHJpbnRmKHN0ZG91dCwgInNlbmRtc2cgZXJyb3IgJWRcbiIsIGVycm5vKTsKCQkJCQll
eGl0KC0xKTsKCQkJCX0KCQkJCWZwcmludGYoc3Rkb3V0LCAic2VuZG1zZygpICVkIGJ5dGUgT0su
IFxuIiwgcmV0KTsKCQkJCQoJCQkJRkRfWkVSTygmcmVhZF9zZXQpOwoJCQkJRkRfU0VUKHMsICZy
ZWFkX3NldCk7CgkJCQlicmVhazsKCQkJfQoJCX0KCQkKCX0KCWZwcmludGYoc3Rkb3V0LCJHT09E
IEJZIFxuIik7CglleGl0ICgwKTsKfQo=

--Multipart_Mon__7_Jan_2002_17:39:44_+0900_083e6930--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/