Skip to content

Commit

Permalink
Revert "Fold uevent message origin checking from init into libcutils."
Browse files Browse the repository at this point in the history
This reverts commit 8405ec0.

The original change does not compile.
  • Loading branch information
nickkral committed Apr 27, 2011
1 parent 282c2ab commit de9e65d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 108 deletions.
32 changes: 0 additions & 32 deletions include/cutils/uevent.h

This file was deleted.

34 changes: 29 additions & 5 deletions init/devices.c
Expand Up @@ -33,8 +33,6 @@
#include <asm/page.h>
#include <sys/wait.h>

#include <cutils/uevent.h>

#include "devices.h"
#include "util.h"
#include "log.h"
Expand Down Expand Up @@ -591,9 +589,35 @@ static void handle_firmware_event(struct uevent *uevent)
#define UEVENT_MSG_LEN 1024
void handle_device_fd()
{
char msg[UEVENT_MSG_LEN+2];
int n;
while ((n = uevent_checked_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) {
for(;;) {
char msg[UEVENT_MSG_LEN+2];
char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
struct iovec iov = {msg, sizeof(msg)};
struct sockaddr_nl snl;
struct msghdr hdr = {&snl, sizeof(snl), &iov, 1, cred_msg, sizeof(cred_msg), 0};

ssize_t n = recvmsg(device_fd, &hdr, 0);
if (n <= 0) {
break;
}

if ((snl.nl_groups != 1) || (snl.nl_pid != 0)) {
/* ignoring non-kernel netlink multicast message */
continue;
}

struct cmsghdr * cmsg = CMSG_FIRSTHDR(&hdr);
if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
/* no sender credentials received, ignore message */
continue;
}

struct ucred * cred = (struct ucred *)CMSG_DATA(cmsg);
if (cred->uid != 0) {
/* message from non-root user, ignore */
continue;
}

if(n >= UEVENT_MSG_LEN) /* overflow -- discard */
continue;

Expand Down
1 change: 0 additions & 1 deletion libcutils/Android.mk
Expand Up @@ -74,7 +74,6 @@ else
mspace.c \
selector.c \
tztime.c \
uevent.c \
zygote.c

commonHostSources += \
Expand Down
70 changes: 0 additions & 70 deletions libcutils/uevent.c

This file was deleted.

0 comments on commit de9e65d

Please sign in to comment.