Loading trusty/storage/proxy/proxy.c +67 −86 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ #include <getopt.h> #include <stdbool.h> #include <stdint.h> #include <string.h> #include <stdlib.h> #include <string.h> #include <sys/capability.h> #include <sys/prctl.h> #include <sys/stat.h> Loading @@ -40,22 +40,18 @@ static const char *rpmb_devname; static const char* ss_srv_name = STORAGE_DISK_PROXY_PORT; static const char* _sopts = "hp:d:r:"; static const struct option _lopts[] = { {"help", no_argument, NULL, 'h'}, static const struct option _lopts[] = {{"help", no_argument, NULL, 'h'}, {"trusty_dev", required_argument, NULL, 'd'}, {"data_path", required_argument, NULL, 'p'}, {"rpmb_dev", required_argument, NULL, 'r'}, {0, 0, 0, 0} }; {0, 0, 0, 0}}; static void show_usage_and_exit(int code) { static void show_usage_and_exit(int code) { ALOGE("usage: storageproxyd -d <trusty_dev> -p <data_path> -r <rpmb_dev>\n"); exit(code); } static int drop_privs(void) { static int drop_privs(void) { struct __user_cap_header_struct capheader; struct __user_cap_data_struct capdata[2]; Loading Loading @@ -95,12 +91,10 @@ static int drop_privs(void) return 0; } static int handle_req(struct storage_msg *msg, const void *req, size_t req_len) { static int handle_req(struct storage_msg* msg, const void* req, size_t req_len) { int rc; if ((msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) && (msg->cmd != STORAGE_RPMB_SEND)) { if ((msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) && (msg->cmd != STORAGE_RPMB_SEND)) { /* * handling post commit messages on non rpmb commands are not * implemented as there is no use case for this yet. Loading Loading @@ -164,37 +158,31 @@ static int handle_req(struct storage_msg *msg, const void *req, size_t req_len) return rc; } static int proxy_loop(void) { static int proxy_loop(void) { ssize_t rc; struct storage_msg msg; /* enter main message handling loop */ while (true) { /* get incoming message */ rc = ipc_get_msg(&msg, req_buffer, REQ_BUFFER_SIZE); if (rc < 0) return rc; if (rc < 0) return rc; /* handle request */ req_buffer[rc] = 0; /* force zero termination */ rc = handle_req(&msg, req_buffer, rc); if (rc) return rc; if (rc) return rc; } return 0; } static void parse_args(int argc, char *argv[]) { static void parse_args(int argc, char* argv[]) { int opt; int oidx = 0; while ((opt = getopt_long(argc, argv, _sopts, _lopts, &oidx)) != -1) { switch (opt) { case 'd': trusty_devname = strdup(optarg); break; Loading @@ -213,9 +201,7 @@ static void parse_args(int argc, char *argv[]) } } if (ss_data_root == NULL || trusty_devname == NULL || rpmb_devname == NULL) { if (ss_data_root == NULL || trusty_devname == NULL || rpmb_devname == NULL) { ALOGE("missing required argument(s)\n"); show_usage_and_exit(EXIT_FAILURE); } Loading @@ -226,31 +212,26 @@ static void parse_args(int argc, char *argv[]) ALOGI("rpmb dev: %s\n", rpmb_devname); } int main(int argc, char *argv[]) { int main(int argc, char* argv[]) { int rc; /* drop privileges */ if (drop_privs() < 0) return EXIT_FAILURE; if (drop_privs() < 0) return EXIT_FAILURE; /* parse arguments */ parse_args(argc, argv); /* initialize secure storage directory */ rc = storage_init(ss_data_root); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* open rpmb device */ rc = rpmb_open(rpmb_devname); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* connect to Trusty secure storage server */ rc = ipc_connect(trusty_devname, ss_srv_name); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* enter main loop */ rc = proxy_loop(); Loading trusty/storage/proxy/rpmb.c +15 −30 Original line number Diff line number Diff line Loading @@ -54,14 +54,12 @@ static uint8_t read_buf[4096]; #ifdef RPMB_DEBUG static void print_buf(const char *prefix, const uint8_t *buf, size_t size) { static void print_buf(const char* prefix, const uint8_t* buf, size_t size) { size_t i; printf("%s @%p [%zu]", prefix, buf, size); for (i = 0; i < size; i++) { if (i && i % 32 == 0) printf("\n%*s", (int) strlen(prefix), ""); if (i && i % 32 == 0) printf("\n%*s", (int)strlen(prefix), ""); printf(" %02x", buf[i]); } printf("\n"); Loading @@ -70,9 +68,7 @@ static void print_buf(const char *prefix, const uint8_t *buf, size_t size) #endif int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) { int rpmb_send(struct storage_msg* msg, const void* r, size_t req_len) { int rc; struct { struct mmc_ioc_multi_cmd multi; Loading @@ -82,17 +78,14 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) const struct storage_rpmb_send_req* req = r; if (req_len < sizeof(*req)) { ALOGW("malformed rpmb request: invalid length (%zu < %zu)\n", req_len, sizeof(*req)); ALOGW("malformed rpmb request: invalid length (%zu < %zu)\n", req_len, sizeof(*req)); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; } size_t expected_len = sizeof(*req) + req->reliable_write_size + req->write_size; size_t expected_len = sizeof(*req) + req->reliable_write_size + req->write_size; if (req_len != expected_len) { ALOGW("malformed rpmb request: invalid length (%zu != %zu)\n", req_len, expected_len); ALOGW("malformed rpmb request: invalid length (%zu != %zu)\n", req_len, expected_len); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; } Loading Loading @@ -143,8 +136,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) } if (req->read_size) { if (req->read_size % MMC_BLOCK_SIZE != 0 || req->read_size > sizeof(read_buf)) { if (req->read_size % MMC_BLOCK_SIZE != 0 || req->read_size > sizeof(read_buf)) { ALOGE("%s: invalid read size %u\n", __func__, req->read_size); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; Loading @@ -152,8 +144,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) cmd->write_flag = MMC_WRITE_FLAG_R; cmd->opcode = MMC_READ_MULTIPLE_BLOCK; cmd->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC, cmd->blksz = MMC_BLOCK_SIZE; cmd->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC, cmd->blksz = MMC_BLOCK_SIZE; cmd->blocks = req->read_size / MMC_BLOCK_SIZE; mmc_ioc_cmd_set_data((*cmd), read_buf); #ifdef RPMB_DEBUG Loading @@ -170,8 +161,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) goto err_response; } #ifdef RPMB_DEBUG if (req->read_size) print_buf("response: ", read_buf, req->read_size); if (req->read_size) print_buf("response: ", read_buf, req->read_size); #endif if (msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) { Loading @@ -188,24 +178,19 @@ err_response: return ipc_respond(msg, NULL, 0); } int rpmb_open(const char *rpmb_devname) { int rpmb_open(const char* rpmb_devname) { int rc; rc = open(rpmb_devname, O_RDWR, 0); if (rc < 0) { ALOGE("unable (%d) to open rpmb device '%s': %s\n", errno, rpmb_devname, strerror(errno)); ALOGE("unable (%d) to open rpmb device '%s': %s\n", errno, rpmb_devname, strerror(errno)); return rc; } rpmb_fd = rc; return 0; } void rpmb_close(void) { void rpmb_close(void) { close(rpmb_fd); rpmb_fd = -1; } trusty/storage/proxy/rpmb.h +2 −2 File changed.Contains only whitespace changes. Show changes Loading
trusty/storage/proxy/proxy.c +67 −86 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ #include <getopt.h> #include <stdbool.h> #include <stdint.h> #include <string.h> #include <stdlib.h> #include <string.h> #include <sys/capability.h> #include <sys/prctl.h> #include <sys/stat.h> Loading @@ -40,22 +40,18 @@ static const char *rpmb_devname; static const char* ss_srv_name = STORAGE_DISK_PROXY_PORT; static const char* _sopts = "hp:d:r:"; static const struct option _lopts[] = { {"help", no_argument, NULL, 'h'}, static const struct option _lopts[] = {{"help", no_argument, NULL, 'h'}, {"trusty_dev", required_argument, NULL, 'd'}, {"data_path", required_argument, NULL, 'p'}, {"rpmb_dev", required_argument, NULL, 'r'}, {0, 0, 0, 0} }; {0, 0, 0, 0}}; static void show_usage_and_exit(int code) { static void show_usage_and_exit(int code) { ALOGE("usage: storageproxyd -d <trusty_dev> -p <data_path> -r <rpmb_dev>\n"); exit(code); } static int drop_privs(void) { static int drop_privs(void) { struct __user_cap_header_struct capheader; struct __user_cap_data_struct capdata[2]; Loading Loading @@ -95,12 +91,10 @@ static int drop_privs(void) return 0; } static int handle_req(struct storage_msg *msg, const void *req, size_t req_len) { static int handle_req(struct storage_msg* msg, const void* req, size_t req_len) { int rc; if ((msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) && (msg->cmd != STORAGE_RPMB_SEND)) { if ((msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) && (msg->cmd != STORAGE_RPMB_SEND)) { /* * handling post commit messages on non rpmb commands are not * implemented as there is no use case for this yet. Loading Loading @@ -164,37 +158,31 @@ static int handle_req(struct storage_msg *msg, const void *req, size_t req_len) return rc; } static int proxy_loop(void) { static int proxy_loop(void) { ssize_t rc; struct storage_msg msg; /* enter main message handling loop */ while (true) { /* get incoming message */ rc = ipc_get_msg(&msg, req_buffer, REQ_BUFFER_SIZE); if (rc < 0) return rc; if (rc < 0) return rc; /* handle request */ req_buffer[rc] = 0; /* force zero termination */ rc = handle_req(&msg, req_buffer, rc); if (rc) return rc; if (rc) return rc; } return 0; } static void parse_args(int argc, char *argv[]) { static void parse_args(int argc, char* argv[]) { int opt; int oidx = 0; while ((opt = getopt_long(argc, argv, _sopts, _lopts, &oidx)) != -1) { switch (opt) { case 'd': trusty_devname = strdup(optarg); break; Loading @@ -213,9 +201,7 @@ static void parse_args(int argc, char *argv[]) } } if (ss_data_root == NULL || trusty_devname == NULL || rpmb_devname == NULL) { if (ss_data_root == NULL || trusty_devname == NULL || rpmb_devname == NULL) { ALOGE("missing required argument(s)\n"); show_usage_and_exit(EXIT_FAILURE); } Loading @@ -226,31 +212,26 @@ static void parse_args(int argc, char *argv[]) ALOGI("rpmb dev: %s\n", rpmb_devname); } int main(int argc, char *argv[]) { int main(int argc, char* argv[]) { int rc; /* drop privileges */ if (drop_privs() < 0) return EXIT_FAILURE; if (drop_privs() < 0) return EXIT_FAILURE; /* parse arguments */ parse_args(argc, argv); /* initialize secure storage directory */ rc = storage_init(ss_data_root); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* open rpmb device */ rc = rpmb_open(rpmb_devname); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* connect to Trusty secure storage server */ rc = ipc_connect(trusty_devname, ss_srv_name); if (rc < 0) return EXIT_FAILURE; if (rc < 0) return EXIT_FAILURE; /* enter main loop */ rc = proxy_loop(); Loading
trusty/storage/proxy/rpmb.c +15 −30 Original line number Diff line number Diff line Loading @@ -54,14 +54,12 @@ static uint8_t read_buf[4096]; #ifdef RPMB_DEBUG static void print_buf(const char *prefix, const uint8_t *buf, size_t size) { static void print_buf(const char* prefix, const uint8_t* buf, size_t size) { size_t i; printf("%s @%p [%zu]", prefix, buf, size); for (i = 0; i < size; i++) { if (i && i % 32 == 0) printf("\n%*s", (int) strlen(prefix), ""); if (i && i % 32 == 0) printf("\n%*s", (int)strlen(prefix), ""); printf(" %02x", buf[i]); } printf("\n"); Loading @@ -70,9 +68,7 @@ static void print_buf(const char *prefix, const uint8_t *buf, size_t size) #endif int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) { int rpmb_send(struct storage_msg* msg, const void* r, size_t req_len) { int rc; struct { struct mmc_ioc_multi_cmd multi; Loading @@ -82,17 +78,14 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) const struct storage_rpmb_send_req* req = r; if (req_len < sizeof(*req)) { ALOGW("malformed rpmb request: invalid length (%zu < %zu)\n", req_len, sizeof(*req)); ALOGW("malformed rpmb request: invalid length (%zu < %zu)\n", req_len, sizeof(*req)); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; } size_t expected_len = sizeof(*req) + req->reliable_write_size + req->write_size; size_t expected_len = sizeof(*req) + req->reliable_write_size + req->write_size; if (req_len != expected_len) { ALOGW("malformed rpmb request: invalid length (%zu != %zu)\n", req_len, expected_len); ALOGW("malformed rpmb request: invalid length (%zu != %zu)\n", req_len, expected_len); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; } Loading Loading @@ -143,8 +136,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) } if (req->read_size) { if (req->read_size % MMC_BLOCK_SIZE != 0 || req->read_size > sizeof(read_buf)) { if (req->read_size % MMC_BLOCK_SIZE != 0 || req->read_size > sizeof(read_buf)) { ALOGE("%s: invalid read size %u\n", __func__, req->read_size); msg->result = STORAGE_ERR_NOT_VALID; goto err_response; Loading @@ -152,8 +144,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) cmd->write_flag = MMC_WRITE_FLAG_R; cmd->opcode = MMC_READ_MULTIPLE_BLOCK; cmd->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC, cmd->blksz = MMC_BLOCK_SIZE; cmd->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC, cmd->blksz = MMC_BLOCK_SIZE; cmd->blocks = req->read_size / MMC_BLOCK_SIZE; mmc_ioc_cmd_set_data((*cmd), read_buf); #ifdef RPMB_DEBUG Loading @@ -170,8 +161,7 @@ int rpmb_send(struct storage_msg *msg, const void *r, size_t req_len) goto err_response; } #ifdef RPMB_DEBUG if (req->read_size) print_buf("response: ", read_buf, req->read_size); if (req->read_size) print_buf("response: ", read_buf, req->read_size); #endif if (msg->flags & STORAGE_MSG_FLAG_POST_COMMIT) { Loading @@ -188,24 +178,19 @@ err_response: return ipc_respond(msg, NULL, 0); } int rpmb_open(const char *rpmb_devname) { int rpmb_open(const char* rpmb_devname) { int rc; rc = open(rpmb_devname, O_RDWR, 0); if (rc < 0) { ALOGE("unable (%d) to open rpmb device '%s': %s\n", errno, rpmb_devname, strerror(errno)); ALOGE("unable (%d) to open rpmb device '%s': %s\n", errno, rpmb_devname, strerror(errno)); return rc; } rpmb_fd = rc; return 0; } void rpmb_close(void) { void rpmb_close(void) { close(rpmb_fd); rpmb_fd = -1; }