safe memory allocation flags
PATCH 1/1 safe memory allocation flags
The patch below allows netdev_precondition() to be called safely from interrupt context.
This can occur, for example, in the IP networking input path, which runs under a softirq. Under these conditions, kernel memory needs to be allocated with the GFP_ATOMIC flag. If anyone has seen an oops upon network traffic immedately after booting, this may have been the cause.
- James
Signature · 52 lines
James Morris <[email protected]> diff -urN -X /tmp/xmdiff module.orig/selinux_plug/hooks.c module/selinux_plug/hooks.c --- module.orig/selinux_plug/hooks.c Thu Aug 23 14:20:50 2001 +++ module/selinux_plug/hooks.c Thu Sep 6 21:57:33 2001 @@ -308,7 +308,7 @@ { struct netdev_security_struct *nsec = dev->security; - nsec = kmalloc(sizeof(struct netdev_security_struct), GFP_KERNEL); + nsec = kmalloc(sizeof(struct netdev_security_struct), SAFE_ALLOC); if (!nsec) return -ENOMEM; memset(nsec, 0, sizeof(struct netdev_security_struct)); diff -urN -X /tmp/xmdiff module.orig/selinux_plug/include/linux/flask/flask_types.h module/selinux_plug/include/linux/flask/flask_types.h --- module.orig/selinux_plug/include/linux/flask/flask_types.h Thu Jul 19 06:38:10 2001 +++ module/selinux_plug/include/linux/flask/flask_types.h Thu Sep 6 21:58:37 2001 @@ -76,5 +76,15 @@ #define CUR_SID current->sid +#ifdef __KERNEL__ +/* + * Use this for memory allocation flags (e.g. for kmalloc()) when the interrupt + * state is unknown. + */ +#include <linux/interrupt.h> + +#define SAFE_ALLOC (in_interrupt () ? GFP_ATOMIC : GFP_KERNEL) +#endif + #endif diff -urN -X /tmp/xmdiff module.orig/selinux_plug/ss/global.h module/selinux_plug/ss/global.h --- module.orig/selinux_plug/ss/global.h Thu Jul 19 06:38:07 2001 +++ module/selinux_plug/ss/global.h Thu Sep 6 22:19:22 2001 @@ -77,7 +77,7 @@ #include <asm/uaccess.h> #include "selinux_plug.h" -#define malloc(size) kmalloc(size, GFP_ATOMIC) +#define malloc(size) kmalloc(size, SAFE_ALLOC) #define free(ptr) kfree(ptr) typedef struct file FILE; -- You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.