Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4391883yba; Tue, 9 Apr 2019 18:18:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMhVkWn6Id+eeH4qwK/aqe/noHpSjClP2hT7UGUMjndSCVLUSOI2qsavQa5IYjnhW6Ety1 X-Received: by 2002:a17:902:2a89:: with SMTP id j9mr40895748plb.272.1554859135993; Tue, 09 Apr 2019 18:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554859135; cv=none; d=google.com; s=arc-20160816; b=j68bf7XN2F3oD5GicFGOZsbHfRezKwIOKQV7fw1fEnsSQGsIfRNS416FmlHARo0OhM eyw1OVwlW2dQGJUeuTU1H+QDcV2IDzLTViUknAT+lWHLUro70woA1PBgmVmwcyRr/Aar zG4D5QDIA3YOPcZgXcu6BwJKW/igvN5cee1YcjvyF3wufa/05GZVHZO0gDB4yGzKF7ff NRTfd0234zErzie0Gr9U/K+q+taUOe4wl/Pun4dSXFlCzs3mBevClNgM6Yk/Bf0YAi63 NY5UlcJFh1NkK+dBBPsSWAZZ8aYtP00c6u7XglzVqiEyz5ueRKANEvw4GWzQo9PXswGp 0uIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LRe7y/AmJSwRL6mJ4EhTLWkHwjbyqszlgX6hCqpGIpA=; b=Yt1WUqmGtukesQ28TWjevVpO75W5zwdhgRnZLuV6q3djIo4HPvEe7CA/Q//Ox44E1f G3cTvUP4V59x8VpfupDm5zh71XBj1uGxM1GlaXEZS1HEpagg5yFyp7IBHZJRsOp9wwYL LToEP1PLgq+2N30BZlxwgVJGQcTu2rMFunwp95Bj3+zvQR5OcPuEThcOMtHVdjEi+AiB qSD/kIBGr5VXVOeR6umLqUT94MXHXhJ0ubAZkj8qmYY7Y87++Gpz6Ii8yKCWrU/OVd+F SeHrBU//edYFAZK/eHfuIV24UVmweWsFfgGbkgr1Bxmns+6kvzApDyzaNbfWOjpv9+pF cNgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=bzVa0hQq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71si7397048plc.91.2019.04.09.18.18.40; Tue, 09 Apr 2019 18:18:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=bzVa0hQq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726717AbfDJBR7 (ORCPT + 99 others); Tue, 9 Apr 2019 21:17:59 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33587 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbfDJBR7 (ORCPT ); Tue, 9 Apr 2019 21:17:59 -0400 Received: by mail-pl1-f196.google.com with SMTP id t16so321752plo.0 for ; Tue, 09 Apr 2019 18:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=LRe7y/AmJSwRL6mJ4EhTLWkHwjbyqszlgX6hCqpGIpA=; b=bzVa0hQqSZZ09BDV9/CL4c0IOihjw3kM/nQ7sstg7B6YFJ5f/Q/MfaysxocEws1SJ5 Fg89TSmGZarqjHZgjqJNNZ6G7lOyD/9LPzjofKvB/zY2bjDAeqo1NQYCsXNeVubdkQLg JOplujQg1A0aeGEtyl23gOWwY4Kd2TE9DyTaA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=LRe7y/AmJSwRL6mJ4EhTLWkHwjbyqszlgX6hCqpGIpA=; b=o/sRGlaR/gg4xgZGdSThGQJm8S1/lxQR3K+NaupTanhVkBWaKQBgZ7K1Z+Elts7EUw 0FqBLdpHOxkTlGRZGW2A/8WMYPeurUJDy45INEGdLMKjZ4M+MEhzZvF5surxNrP59tMC gXgAgVo5ucQAZHEAyt5r/1IrRHtZ4bCkeaBS3KAVrXxvLGn40Jr3el8jjKhUdqY15AHD hw84KdbxAnBqPOZhp7KIvCgQnAsOKWhO2xCmnPROrR9KGZDLPUoOBnSuJg8o14RaXO77 ehvxeXrLRrM/pJU6VG50r1yzIpf3TlLpIqtjbO/UykOmsIV549pHPE+BSz4KpCQ5KwMD A2Kw== X-Gm-Message-State: APjAAAU/6FFqEr/waHi4LftY9Hk68RjMtqr9uIisTu/cjOg/mmvtSrId nAttWmWqHSnTHSqzNhDEd0ZYYkDwEuQ= X-Received: by 2002:a17:902:bb84:: with SMTP id m4mr1695508pls.302.1554859077978; Tue, 09 Apr 2019 18:17:57 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id k79sm16509465pfj.28.2019.04.09.18.17.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Apr 2019 18:17:57 -0700 (PDT) Date: Tue, 9 Apr 2019 21:17:56 -0400 From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: paulmck@linux.vnet.ibm.com, keescook@chromium.org, Jessica Yu , kernel-hardening@lists.openwall.com, kernel-team@android.com, mathieu.desnoyers@efficios.com, rcu@vger.kernel.org, rostedt@goodmis.org Subject: Re: [PATCH 2/2] module: Make srcu_struct ptr array as read-only post init Message-ID: <20190410011756.GA78239@google.com> References: <20190410011418.76408-1-joel@joelfernandes.org> <20190410011418.76408-2-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190410011418.76408-2-joel@joelfernandes.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 09, 2019 at 09:14:18PM -0400, Joel Fernandes (Google) wrote: > Since commit title ("srcu: Allocate per-CPU data for DEFINE_SRCU() in > modules"), modules that call DEFINE_{STATIC,}SRCU will have a new array > of srcu_struct pointers which is used by srcu code to initialize and > clean up these structures. > > There is no reason for this array of pointers to be writable, and can > cause security or other hidden bugs. Mark these are read-only after the > module init has completed. > > Suggested-by: paulmck@linux.vnet.ibm.com > Suggested-by: keescook@chromium.org > Signed-off-by: Joel Fernandes (Google) Just wanted to mention, that I tested that the srcu_struct_ptrs array is not writeable any more after init, but doing the following after module_enable_ro() : @@ -3513,6 +3523,14 @@ static noinline int do_init_module(struct module *mod) rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); #endif module_enable_ro(mod, true); + + if (mod->srcu_struct_ptrs) { + // Check if SRCU Access is possible + char x = *(char *)mod->srcu_struct_ptrs; + *(char *)mod->srcu_struct_ptrs = 0; + *(char *)mod->srcu_struct_ptrs = x; + } + mod_tree_remove_init(mod); disable_ro_nx(&mod->init_layout); module_arch_freeing_init(mod); thanks, - Joel > > --- > kernel/module.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/kernel/module.c b/kernel/module.c > index f9221381d076..ed1f2612aebc 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -3301,7 +3301,7 @@ static bool blacklisted(const char *module_name) > core_param(module_blacklist, module_blacklist, charp, 0400); > > /* > - * Mark ro_after_init section with SHF_RO_AFTER_INIT so that > + * These are section names marked with SHF_RO_AFTER_INIT so that > * layout_sections() can put it in the right place. > * Note: ro_after_init sections also have SHF_{WRITE,ALLOC} set. > */ > @@ -3314,6 +3314,13 @@ static char *ro_after_init_sections[] = { > * annotated as such at module load time. > */ > "__jump_table", > + > + /* > + * Used for SRCU structures which need to be initialized/cleaned up > + * by the SRCU notifiers > + */ > + "___srcu_struct_ptrs", > + > NULL > }; > > -- > 2.21.0.392.gf8f6787159e-goog >