summaryrefslogtreecommitdiffstats
path: root/init/devices.c
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2011-04-27 10:21:24 -0700
committerNick Kralevich <nnk@google.com>2011-04-27 10:21:24 -0700
commitde9e65dd6586a1c62fe010f9512e326591a4863d (patch)
tree536b5c05ae62e99b85dda1f3f304b5e1f30da622 /init/devices.c
parent282c2ab408d487d0995362d1b9aa97fe30d97ebd (diff)
downloadsystem_core-de9e65dd6586a1c62fe010f9512e326591a4863d.zip
system_core-de9e65dd6586a1c62fe010f9512e326591a4863d.tar.gz
system_core-de9e65dd6586a1c62fe010f9512e326591a4863d.tar.bz2
Revert "Fold uevent message origin checking from init into libcutils."
This reverts commit 8405ec0e7562a370174d9973dd94984c47e49c36. The original change does not compile.
Diffstat (limited to 'init/devices.c')
-rw-r--r--init/devices.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/init/devices.c b/init/devices.c
index eb5d84e..e73efdf 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -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"
@@ -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;