X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=security%2Fselinux%2Fss%2Favtab.c;h=609ca16be799fe7fce87ce83c680e22179b2b231;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=66fbdbb58be838db92003867d3ed36855a072597;hpb=87fc8d1bb10cd459024a742c6a10961fefcef18f;p=linux-2.6.git diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c index 66fbdbb58..609ca16be 100644 --- a/security/selinux/ss/avtab.c +++ b/security/selinux/ss/avtab.c @@ -303,20 +303,25 @@ void avtab_hash_eval(struct avtab *h, char *tag) int avtab_read_item(void *fp, struct avtab_datum *avdatum, struct avtab_key *avkey) { - __u32 *buf; - __u32 items, items2; + u32 buf[7]; + u32 items, items2; + int rc; memset(avkey, 0, sizeof(struct avtab_key)); memset(avdatum, 0, sizeof(struct avtab_datum)); - buf = next_entry(fp, sizeof(__u32)); - if (!buf) { + rc = next_entry(buf, fp, sizeof(u32)); + if (rc < 0) { printk(KERN_ERR "security: avtab: truncated entry\n"); goto bad; } items2 = le32_to_cpu(buf[0]); - buf = next_entry(fp, sizeof(__u32)*items2); - if (!buf) { + if (items2 > ARRAY_SIZE(buf)) { + printk(KERN_ERR "security: avtab: entry overflow\n"); + goto bad; + } + rc = next_entry(buf, fp, sizeof(u32)*items2); + if (rc < 0) { printk(KERN_ERR "security: avtab: truncated entry\n"); goto bad; } @@ -362,26 +367,29 @@ bad: int avtab_read(struct avtab *a, void *fp, u32 config) { - int i, rc = -EINVAL; + int rc; struct avtab_key avkey; struct avtab_datum avdatum; - u32 *buf; - u32 nel; + u32 buf[1]; + u32 nel, i; - buf = next_entry(fp, sizeof(u32)); - if (!buf) { + rc = next_entry(buf, fp, sizeof(u32)); + if (rc < 0) { printk(KERN_ERR "security: avtab: truncated table\n"); goto bad; } nel = le32_to_cpu(buf[0]); if (!nel) { printk(KERN_ERR "security: avtab: table is empty\n"); + rc = -EINVAL; goto bad; } for (i = 0; i < nel; i++) { - if (avtab_read_item(fp, &avdatum, &avkey)) + if (avtab_read_item(fp, &avdatum, &avkey)) { + rc = -EINVAL; goto bad; + } rc = avtab_insert(a, &avkey, &avdatum); if (rc) { if (rc == -ENOMEM) @@ -407,3 +415,8 @@ void avtab_cache_init(void) sizeof(struct avtab_node), 0, SLAB_PANIC, NULL, NULL); } + +void avtab_cache_destroy(void) +{ + kmem_cache_destroy (avtab_node_cachep); +}