Skip to content

Commit 26045a7

Browse files
Christian Braunerdavem330
authored andcommitted
uevent: add alloc_uevent_skb() helper
This patch adds alloc_uevent_skb() in preparation for follow up patches. Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e33200b commit 26045a7

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

lib/kobject_uevent.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/socket.h>
2323
#include <linux/skbuff.h>
2424
#include <linux/netlink.h>
25+
#include <linux/uidgid.h>
2526
#include <linux/uuid.h>
2627
#include <linux/ctype.h>
2728
#include <net/sock.h>
@@ -296,6 +297,38 @@ static void cleanup_uevent_env(struct subprocess_info *info)
296297
}
297298
#endif
298299

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+
299332
static int kobject_uevent_net_broadcast(struct kobject *kobj,
300333
struct kobj_uevent_env *env,
301334
const char *action_string,
@@ -314,22 +347,10 @@ static int kobject_uevent_net_broadcast(struct kobject *kobj,
314347
continue;
315348

316349
if (!skb) {
317-
/* allocate message with the maximum possible size */
318-
size_t len = strlen(action_string) + strlen(devpath) + 2;
319-
char *scratch;
320-
321350
retval = -ENOMEM;
322-
skb = alloc_skb(len + env->buflen, GFP_KERNEL);
351+
skb = alloc_uevent_skb(env, action_string, devpath);
323352
if (!skb)
324353
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;
333354
}
334355

335356
retval = netlink_broadcast_filtered(uevent_sock, skb_get(skb),

0 commit comments

Comments
 (0)