Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761412AbZDGPY4 (ORCPT ); Tue, 7 Apr 2009 11:24:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753415AbZDGPKa (ORCPT ); Tue, 7 Apr 2009 11:10:30 -0400 Received: from one.firstfloor.org ([213.235.205.2]:41316 "EHLO one.firstfloor.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759282AbZDGPK0 (ORCPT ); Tue, 7 Apr 2009 11:10:26 -0400 From: Andi Kleen References: <20090407509.382219156@firstfloor.org> In-Reply-To: <20090407509.382219156@firstfloor.org> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: [PATCH] [16/16] POISON: Add madvise() based injector for poisoned data Message-Id: <20090407151014.364D81D0470@basil.firstfloor.org> Date: Tue, 7 Apr 2009 17:10:14 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3114 Lines: 96 Impact: optional, useful for debugging Add a new madvice sub command to inject poison for some pages in a process' address space. This is useful for testing the poison page handling. Open issues: - This patch allows root to tie up arbitary amounts of memory. Should this be disabled inside containers? - There's a small race window between getting the page and injecting. The patch drops the ref count because otherwise memory_failure complains about dangling references. In theory with a multi threaded injector one could inject poison for a process foreign page this way. Not a serious issue right now. Signed-off-by: Andi Kleen --- include/asm-generic/mman.h | 1 + mm/madvise.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) Index: linux/mm/madvise.c =================================================================== --- linux.orig/mm/madvise.c 2009-04-07 16:36:29.000000000 +0200 +++ linux/mm/madvise.c 2009-04-07 16:39:39.000000000 +0200 @@ -208,6 +208,38 @@ return error; } +#ifdef CONFIG_MEMORY_FAILURE +/* + * Error injection support for memory error handling. + */ +static int madvise_poison(unsigned long start, unsigned long end) +{ + /* + * RED-PEN + * This allows to tie up arbitary amounts of memory. + * Might be a good idea to disable it inside containers even for root. + */ + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + for (; start < end; start += PAGE_SIZE) { + struct page *p; + int ret = get_user_pages(current, current->mm, start, 1, + 0, 0, &p, NULL); + if (ret != 1) + return ret; + put_page(p); + /* + * RED-PEN page can be reused, but otherwise we'll have to fight with the + * refcnt + */ + printk(KERN_INFO "Injecting memory failure for page %lx at %lx\n", + page_to_pfn(p), start); + memory_failure(page_to_pfn(p), 0); + } + return 0; +} +#endif + static long madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start, unsigned long end, int behavior) @@ -290,6 +322,11 @@ int write; size_t len; +#ifdef CONFIG_MEMORY_FAILURE + if (behavior == MADV_POISON) + return madvise_poison(start, start+len_in); +#endif + write = madvise_need_mmap_write(behavior); if (write) down_write(¤t->mm->mmap_sem); Index: linux/include/asm-generic/mman.h =================================================================== --- linux.orig/include/asm-generic/mman.h 2009-04-07 16:36:29.000000000 +0200 +++ linux/include/asm-generic/mman.h 2009-04-07 16:39:39.000000000 +0200 @@ -34,6 +34,7 @@ #define MADV_REMOVE 9 /* remove these pages & resources */ #define MADV_DONTFORK 10 /* don't inherit across fork */ #define MADV_DOFORK 11 /* do inherit across fork */ +#define MADV_POISON 12 /* poison the page (root only) */ /* compatibility flags */ #define MAP_FILE 0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/