Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752751AbbBWMCL (ORCPT ); Mon, 23 Feb 2015 07:02:11 -0500 Received: from ozlabs.org ([103.22.144.67]:48212 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752372AbbBWMCC (ORCPT ); Mon, 23 Feb 2015 07:02:02 -0500 From: Rusty Russell To: Andrey Ryabinin , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dmitry Vyukov Subject: Re: [PATCH] kasan, module, vmalloc: rework shadow allocation for modules In-Reply-To: <54E6E684.4070806@samsung.com> References: <1424281467-2593-1-git-send-email-a.ryabinin@samsung.com> <87pp96stmz.fsf@rustcorp.com.au> <54E5E355.9020404@samsung.com> <87fva1sajo.fsf@rustcorp.com.au> <54E6E684.4070806@samsung.com> User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Mon, 23 Feb 2015 18:56:12 +1030 Message-ID: <87vbithw4b.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1945 Lines: 50 Andrey Ryabinin writes: > On 02/20/2015 03:15 AM, Rusty Russell wrote: >> Andrey Ryabinin writes: >>> On 02/19/2015 02:10 AM, Rusty Russell wrote: >>>> This is not portable. Other archs don't use vmalloc, or don't use >>>> (or define) MODULES_VADDR. If you really want to hook here, you'd >>>> need a new flag (or maybe use PAGE_KERNEL_EXEC after an audit). >>>> >>> >>> Well, instead of explicit (addr >= MODULES_VADDR && addr < MODULES_END) >>> I could hide this into arch-specific function: 'kasan_need_to_allocate_shadow(const void *addr)' >>> or make make all those functions weak and allow arch code to redefine them. >> >> That adds another layer of indirection. And how would the caller of >> plain vmalloc() even know what to return? >> > > I think I don't understand what do you mean here. vmalloc() callers shouldn't know > anything about kasan/shadow. How else would kasan_need_to_allocate_shadow(const void *addr) work for architectures which don't have a reserved vmalloc region for modules? >> Hmm, how about a hybrid: >> >> 1) Add kasan_module_alloc(p, size) after module alloc as your original. >> 2) Hook into vfree(), and ignore it if you can't find the map. >> > > That should work, but it looks messy IMO. > >> Or is the latter too expensive? >> > > Not sure whether this will be too expensive or not, > but definitely more expensive than simple (addr >= MODULES_VADDR && addr < MODULES_END) check. Sure, if that check were portable. If you ever wanted kasan on other vmalloc addresses it wouldn't work either. I actually think this pattern is the *simplest* solution for auxilliary data like kasan. Cheers, Rusty. -- 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/