Skip to contentSkip to conversation

__sock_create() change

RFC Razvan Deaconescu 4 participants 5 messages May 14, 2007 – May 15, 2007 Kernel janitors

lore
Share & tools
lore
#0 lore raw
Quoted 21 lines · pradeep singh

Hi All,

the __sock_create in net/socket.c has the following code snippet.

if (family = PF_INET && type = SOCK_PACKET) {
     static int warned;
     if (!warned) {
          warned = 1;
          printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", 
current->comm);
     }
     family = PF_PACKET;
}

this may be in place to emit a harmless warning , but why not change it to -
if (family = PF_INET && type = SOCK_PACKET) {

printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
current->comm);

Quoted 6 lines
     family = PF_PACKET;
}

Because anyway if(!warning) is going to result in true everytime we enter the function, as static int warning has scope limited to the outer if block.

Not quite so. The warning variable may only have scope within its block ,but (being static) is stored in a reserved memory area (I think this is called linkage ... not sure though). The second time someone would try creating a socket using PF_INET and SOCK_PACKET, he/she would not get that warning as 'warning' is already set (warning = 1, that is).

Razvan
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 29 lines · Razvan Deaconescu
Quoted 26 lines · pradeep singh

Hi All,

the __sock_create in net/socket.c has the following code snippet.

if (family == PF_INET && type == SOCK_PACKET) {
     static int warned;
     if (!warned) {
          warned = 1;
          printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
current->comm);
     }
     family = PF_PACKET;
}

this may be in place to emit a harmless warning , but why not change it to -
if (family == PF_INET && type == SOCK_PACKET) {

printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n",
current->comm);

     family = PF_PACKET;
}

Because anyway if(!warning) is going to result in true everytime we enter the function, as static int warning has scope limited to the outer

Quoted 7 lines
Quoted 1 line

if block.

Not quite so. The warning variable may only have scope within its block ,but (being static) is stored in a reserved memory area (I think this is called linkage ... not sure though). The second time someone would try creating a socket using PF_INET and SOCK_PACKET, he/she would not get that warning as 'warning' is already set (warning = 1, that is).

You are right indeed, static does have internal linkage. Messed that up though :-(.

But why would we want
to issues warning only once and not each time the socket is created for SOCK_PAKCET type?

Thanks for correcting Razvan.

~psr

Razvan

Quoted 1 line
Signature · 1 line
play the game

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#3 lore raw
In reply to Razvan Deaconescu
Quoted 1 line · Arjan van de Ven

because then a normal user can overflood the system log ;)

they can do that anyhow:

main()

{
    for (;;) {
        if (!fork())
	    *(char*)(0ul) = 1;
        sleep(1);
    }
}

would probably work pretty well on some platforms to overflow the system log and not go noticed... (i'm sure if you look there are lots of ways a local user can do similar things)

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

#4 lore raw
In reply to Razvan Deaconescu
Quoted 9 lines · Arjan van de Ven
Quoted 3 lines · pradeep singh

But why would we want
to issues warning only once and not each time the socket is created for

SOCK_PAKCET type?

because then a normal user can overflood the system log ;)

Oh, that explains a lot.
Thank you Arjan.
~psr

Signature · 1 line
play the game

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors