aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/ss/ebitmap.c8
-rw-r--r--security/selinux/ss/mls.c17
-rw-r--r--security/selinux/ss/services.c18
3 files changed, 30 insertions, 13 deletions
diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c
index cfed1d30fa6a..d539346ab3a2 100644
--- a/security/selinux/ss/ebitmap.c
+++ b/security/selinux/ss/ebitmap.c
@@ -93,11 +93,15 @@ int ebitmap_export(const struct ebitmap *src,
93 size_t bitmap_byte; 93 size_t bitmap_byte;
94 unsigned char bitmask; 94 unsigned char bitmask;
95 95
96 if (src->highbit == 0) {
97 *dst = NULL;
98 *dst_len = 0;
99 return 0;
100 }
101
96 bitmap_len = src->highbit / 8; 102 bitmap_len = src->highbit / 8;
97 if (src->highbit % 7) 103 if (src->highbit % 7)
98 bitmap_len += 1; 104 bitmap_len += 1;
99 if (bitmap_len == 0)
100 return -EINVAL;
101 105
102 bitmap = kzalloc((bitmap_len & ~(sizeof(MAPTYPE) - 1)) + 106 bitmap = kzalloc((bitmap_len & ~(sizeof(MAPTYPE) - 1)) +
103 sizeof(MAPTYPE), 107 sizeof(MAPTYPE),
diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c
index c713af23250a..2cca8e251624 100644
--- a/security/selinux/ss/mls.c
+++ b/security/selinux/ss/mls.c
@@ -640,8 +640,13 @@ int mls_export_cat(const struct context *context,
640{ 640{
641 int rc = -EPERM; 641 int rc = -EPERM;
642 642
643 if (!selinux_mls_enabled) 643 if (!selinux_mls_enabled) {
644 *low = NULL;
645 *low_len = 0;
646 *high = NULL;
647 *high_len = 0;
644 return 0; 648 return 0;
649 }
645 650
646 if (low != NULL) { 651 if (low != NULL) {
647 rc = ebitmap_export(&context->range.level[0].cat, 652 rc = ebitmap_export(&context->range.level[0].cat,
@@ -661,10 +666,16 @@ int mls_export_cat(const struct context *context,
661 return 0; 666 return 0;
662 667
663export_cat_failure: 668export_cat_failure:
664 if (low != NULL) 669 if (low != NULL) {
665 kfree(*low); 670 kfree(*low);
666 if (high != NULL) 671 *low = NULL;
672 *low_len = 0;
673 }
674 if (high != NULL) {
667 kfree(*high); 675 kfree(*high);
676 *high = NULL;
677 *high_len = 0;
678 }
668 return rc; 679 return rc;
669} 680}
670 681
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 18274b005090..b1f6fb36c699 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -2399,31 +2399,33 @@ static int selinux_netlbl_socket_setsid(struct socket *sock, u32 sid)
2399 if (!ss_initialized) 2399 if (!ss_initialized)
2400 return 0; 2400 return 0;
2401 2401
2402 netlbl_secattr_init(&secattr);
2403
2402 POLICY_RDLOCK; 2404 POLICY_RDLOCK;
2403 2405
2404 ctx = sidtab_search(&sidtab, sid); 2406 ctx = sidtab_search(&sidtab, sid);
2405 if (ctx == NULL) 2407 if (ctx == NULL)
2406 goto netlbl_socket_setsid_return; 2408 goto netlbl_socket_setsid_return;
2407 2409
2408 netlbl_secattr_init(&secattr);
2409 secattr.domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1], 2410 secattr.domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1],
2410 GFP_ATOMIC); 2411 GFP_ATOMIC);
2411 mls_export_lvl(ctx, &secattr.mls_lvl, NULL); 2412 mls_export_lvl(ctx, &secattr.mls_lvl, NULL);
2412 secattr.mls_lvl_vld = 1; 2413 secattr.mls_lvl_vld = 1;
2413 mls_export_cat(ctx, 2414 rc = mls_export_cat(ctx,
2414 &secattr.mls_cat, 2415 &secattr.mls_cat,
2415 &secattr.mls_cat_len, 2416 &secattr.mls_cat_len,
2416 NULL, 2417 NULL,
2417 NULL); 2418 NULL);
2419 if (rc != 0)
2420 goto netlbl_socket_setsid_return;
2418 2421
2419 rc = netlbl_socket_setattr(sock, &secattr); 2422 rc = netlbl_socket_setattr(sock, &secattr);
2420 if (rc == 0) 2423 if (rc == 0)
2421 sksec->nlbl_state = NLBL_LABELED; 2424 sksec->nlbl_state = NLBL_LABELED;
2422 2425
2423 netlbl_secattr_destroy(&secattr);
2424
2425netlbl_socket_setsid_return: 2426netlbl_socket_setsid_return:
2426 POLICY_RDUNLOCK; 2427 POLICY_RDUNLOCK;
2428 netlbl_secattr_destroy(&secattr);
2427 return rc; 2429 return rc;
2428} 2430}
2429 2431