22
22
#include <linux/socket.h>
23
23
#include <linux/skbuff.h>
24
24
#include <linux/netlink.h>
25
+ #include <linux/uidgid.h>
25
26
#include <linux/uuid.h>
26
27
#include <linux/ctype.h>
27
28
#include <net/sock.h>
@@ -296,6 +297,38 @@ static void cleanup_uevent_env(struct subprocess_info *info)
296
297
}
297
298
#endif
298
299
300
+ #ifdef CONFIG_NET
301
+ static struct sk_buff * alloc_uevent_skb (struct kobj_uevent_env * env ,
302
+ const char * action_string ,
303
+ const char * devpath )
304
+ {
305
+ struct netlink_skb_parms * parms ;
306
+ struct sk_buff * skb = NULL ;
307
+ char * scratch ;
308
+ size_t len ;
309
+
310
+ /* allocate message with maximum possible size */
311
+ len = strlen (action_string ) + strlen (devpath ) + 2 ;
312
+ skb = alloc_skb (len + env -> buflen , GFP_KERNEL );
313
+ if (!skb )
314
+ return NULL ;
315
+
316
+ /* add header */
317
+ scratch = skb_put (skb , len );
318
+ sprintf (scratch , "%s@%s" , action_string , devpath );
319
+
320
+ skb_put_data (skb , env -> buf , env -> buflen );
321
+
322
+ parms = & NETLINK_CB (skb );
323
+ parms -> creds .uid = GLOBAL_ROOT_UID ;
324
+ parms -> creds .gid = GLOBAL_ROOT_GID ;
325
+ parms -> dst_group = 1 ;
326
+ parms -> portid = 0 ;
327
+
328
+ return skb ;
329
+ }
330
+ #endif
331
+
299
332
static int kobject_uevent_net_broadcast (struct kobject * kobj ,
300
333
struct kobj_uevent_env * env ,
301
334
const char * action_string ,
@@ -314,22 +347,10 @@ static int kobject_uevent_net_broadcast(struct kobject *kobj,
314
347
continue ;
315
348
316
349
if (!skb ) {
317
- /* allocate message with the maximum possible size */
318
- size_t len = strlen (action_string ) + strlen (devpath ) + 2 ;
319
- char * scratch ;
320
-
321
350
retval = - ENOMEM ;
322
- skb = alloc_skb ( len + env -> buflen , GFP_KERNEL );
351
+ skb = alloc_uevent_skb ( env , action_string , devpath );
323
352
if (!skb )
324
353
continue ;
325
-
326
- /* add header */
327
- scratch = skb_put (skb , len );
328
- sprintf (scratch , "%s@%s" , action_string , devpath );
329
-
330
- skb_put_data (skb , env -> buf , env -> buflen );
331
-
332
- NETLINK_CB (skb ).dst_group = 1 ;
333
354
}
334
355
335
356
retval = netlink_broadcast_filtered (uevent_sock , skb_get (skb ),
0 commit comments