Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753631AbbBTHrY (ORCPT ); Fri, 20 Feb 2015 02:47:24 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:38341 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753208AbbBTHrX (ORCPT ); Fri, 20 Feb 2015 02:47:23 -0500 X-AuditID: cbfec7f4-b7f126d000001e9a-7e-54e6e5f77166 Message-id: <54E6E684.4070806@samsung.com> Date: Fri, 20 Feb 2015 10:47:16 +0300 From: Andrey Ryabinin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 To: Rusty Russell , 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 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> In-reply-to: <87fva1sajo.fsf@rustcorp.com.au> Content-type: text/plain; charset=utf-8 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrALMWRmVeSWpSXmKPExsVy+t/xK7rfnz4LMfi/XsNizvo1bBYTHrax W1zeNYfN4t6a/6wWN6ddYHFg9ViwqdRj06dJ7B4nZvxm8Vix4QSzx+dNcgGsUVw2Kak5mWWp Rfp2CVwZ1940sBas56/o2X2BrYFxJk8XIyeHhICJxLyT69kgbDGJC/dAbC4OIYGljBJvjm5k gXCamSTenX3DDlLFK6Alcf3ablYQm0VAVWLi1VZGEJtNQE/i36ztYJNEBSIk5h97zQxRLyjx Y/I9FhBbRCBMou1pM9AcDg5mgSiJhUu1QcLCAsESt77vYIfYtYpRor37IytIDaeArsTtHQkQ 5eoSU6bkgpQzC8hLbF7zlnkCo8AsJAtmIVTNQlK1gJF5FaNoamlyQXFSeq6hXnFibnFpXrpe cn7uJkZIKH/Zwbj4mNUhRgEORiUe3h97noUIsSaWFVfmHmKU4GBWEuEtuwgU4k1JrKxKLcqP LyrNSS0+xMjEwSnVwKg8S9FV6HIjo3GhfN9bt3zPx0/4hZqkM+PkTE5+MDD7dsy26H/vP46p BXsuJrvfqLww00t231mRHxGft4ncX69webrkH/f4nyrpDwymvVyx2NjEWSIn9TfHc4anL/bd KvjY+eLI96BFjdUr974QVywV3rHorHNk1oqOZY1sByc6p1g5n3pwfbESS3FGoqEWc1FxIgDT +Cm2QwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2161 Lines: 56 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. You were concerned that this patch is not portable, so I suggested to hide arch specific part in arch code. That's it. >>> Thus I think modifying the callers is the better choice. >>> >> >> I could suggest following (though, I still prefer 'modifying vmalloc' approach): >> * In do_init_module(), instead of call_rcu(&freeinit->rcu, do_free_init); >> use synchronyze_rcu() + module_memfree(). Of course this will be >> under CONFIG_KASAN. > > But it would be slow, and a disparate code path, which is usually a bad > idea. > >> As you said there other module_memfree() users, so what if they will decide >> to free memory in atomic context? > > 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. -- 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/