Skip to content

Commit 82b88bb

Browse files
committed
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/selinux into for-linus
2 parents 60b8b1d + ded5098 commit 82b88bb

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎security/selinux/selinuxfs.c‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/audit.h>
3030
#include <linux/uaccess.h>
3131
#include <linux/kobject.h>
32+
#include <linux/ctype.h>
3233

3334
/* selinuxfs pseudo filesystem for exporting the security policy API.
3435
Based on the proc code and the fs/nfsd/nfsctl.c code. */
@@ -751,6 +752,14 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
751752
return length;
752753
}
753754

755+
static inline int hexcode_to_int(int code) {
756+
if (code == '\0' || !isxdigit(code))
757+
return -1;
758+
if (isdigit(code))
759+
return code - '0';
760+
return tolower(code) - 'a' + 10;
761+
}
762+
754763
static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
755764
{
756765
char *scon = NULL, *tcon = NULL;
@@ -785,8 +794,34 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
785794
nargs = sscanf(buf, "%s %s %hu %s", scon, tcon, &tclass, namebuf);
786795
if (nargs < 3 || nargs > 4)
787796
goto out;
788-
if (nargs == 4)
797+
if (nargs == 4) {
798+
/*
799+
* If and when the name of new object to be queried contains
800+
* either whitespace or multibyte characters, they shall be
801+
* encoded based on the percentage-encoding rule.
802+
* If not encoded, the sscanf logic picks up only left-half
803+
* of the supplied name; splitted by a whitespace unexpectedly.
804+
*/
805+
char *r, *w;
806+
int c1, c2;
807+
808+
r = w = namebuf;
809+
do {
810+
c1 = *r++;
811+
if (c1 == '+')
812+
c1 = ' ';
813+
else if (c1 == '%') {
814+
if ((c1 = hexcode_to_int(*r++)) < 0)
815+
goto out;
816+
if ((c2 = hexcode_to_int(*r++)) < 0)
817+
goto out;
818+
c1 = (c1 << 4) | c2;
819+
}
820+
*w++ = c1;
821+
} while (c1 != '\0');
822+
789823
objname = namebuf;
824+
}
790825

791826
length = security_context_to_sid(scon, strlen(scon) + 1, &ssid);
792827
if (length)

‎security/selinux/ss/policydb.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,6 +3222,9 @@ static int filename_trans_write(struct policydb *p, void *fp)
32223222
__le32 buf[1];
32233223
int rc;
32243224

3225+
if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
3226+
return 0;
3227+
32253228
nel = 0;
32263229
rc = hashtab_map(p->filename_trans, hashtab_cnt, &nel);
32273230
if (rc)

0 commit comments

Comments
 (0)