Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6209631yba; Thu, 11 Apr 2019 14:34:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMyms6H/c2t5L3zn7+AvHdrkt2F6nWNPUUbxJka/q3f2sMI28CoNw+b7Tg5B8Lqs71ARbO X-Received: by 2002:a63:4241:: with SMTP id p62mr49509324pga.379.1555018445844; Thu, 11 Apr 2019 14:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555018445; cv=none; d=google.com; s=arc-20160816; b=Clkizq7o9Qfam0u6ugVbNXRhglDresiEem4Q4XJJT9b6rHbgxpuDvZ+z5C7xjartgf JQKMggyaUhujtqsZJ4G1ClZcvytyQDkIBw01izxN3AFIUQZLLP6tHSOjiR+he3JUetHC QaNubQ2XC/j7do+La9RAFKtjAQOgnhyjhQ9nvYtnwyUo1itS93HiZEB27jtb1Pk7IKEe 5j9SeSgcsRa2fAO319Ret3dhVgQK4vUMDFhKnvz+fuBddKwlN6fcU+pwB5CH8wbdSUoh pghhw6EPxIVsTT06LbL+V1DNJlPhANzpQeuag8cRwyW6WLS49Q1XlqNC7lCA8973aZXs F2YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=8zbXd624SFmflqHyowLhB2PIyR/RbEm63erlSzfHMlo=; b=COmszLnBIQw+CyrViclMvMimBFCPQ0vlcdo6TTVKbk8/opV6fNLhZRpfRDOlu4HsmF s8LNrhohb4kcZy39d2ZzCYfRtJ6vbofPcF/HysCKOiYaxvzXZ0yt150t3Ptsp+EHOBOo HgNV1pjHub1Th4zjhgsnz0/Lw2ticeoH8RCfGbqayI11uQSDMJUlwo1lM+BU7su2sbi2 3+VXm2OqbTqfst2cy9EFepnS0v0nL2rxIHB3gYmRHKGWMgVNESLwykHHmAzEh1osKkfk GAAsNh/Zl322trbpHZTEPFWM75AYOLkCXy/ZkroX3ZWCdaZF/100FWcynHt/AVpJXXMm 6AWg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11si37171879pfa.110.2019.04.11.14.33.50; Thu, 11 Apr 2019 14:34:05 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727024AbfDKVcC (ORCPT + 99 others); Thu, 11 Apr 2019 17:32:02 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60988 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726872AbfDKVcC (ORCPT ); Thu, 11 Apr 2019 17:32:02 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3BLEjWI118901 for ; Thu, 11 Apr 2019 17:32:01 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rtc2wbvg6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Apr 2019 17:32:00 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Apr 2019 22:32:00 +0100 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 11 Apr 2019 22:31:55 +0100 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3BLVsN230343340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Apr 2019 21:31:54 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 801A4B2065; Thu, 11 Apr 2019 21:31:54 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 627C0B2066; Thu, 11 Apr 2019 21:31:54 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.188]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 11 Apr 2019 21:31:54 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id DE25C16C36C6; Thu, 11 Apr 2019 14:31:55 -0700 (PDT) Date: Thu, 11 Apr 2019 14:31:55 -0700 From: "Paul E. McKenney" To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , rostedt@goodmis.org, mathieu.desnoyers@efficios.com, rcu@vger.kernel.org, kernel-hardening@lists.openwall.com, kernel-team@android.com, Josh Triplett , Lai Jiangshan Subject: Re: [PATCH] module: Make srcu_struct ptr array as read-only Reply-To: paulmck@linux.ibm.com References: <20190411202421.131779-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190411202421.131779-1-joel@joelfernandes.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19041121-0068-0000-0000-000003B3E9FB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010911; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000284; SDB=6.01187707; UDB=6.00622151; IPR=6.00968471; MB=3.00026399; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-11 21:31:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041121-0069-0000-0000-000048200CAB Message-Id: <20190411213155.GD14111@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-11_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904110137 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 11, 2019 at 04:24:21PM -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 and save valuable per-cpu reserved space. > > 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. > > Tested with the following diff to ensure array not writable: > > (diff is a bit reduced to avoid patch command getting confused) > a/kernel/module.c > b/kernel/module.c > -3506,6 +3506,14 static noinline int do_init_module [snip] > rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); > #endif > module_enable_ro(mod, true); > + > + if (mod->srcu_struct_ptrs) { > + // Check if srcu_struct_ptrs 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); > > Cc: Rasmus Villemoes > Cc: paulmck@linux.vnet.ibm.com > Cc: rostedt@goodmis.org > Cc: mathieu.desnoyers@efficios.com > Cc: rcu@vger.kernel.org > Cc: kernel-hardening@lists.openwall.com > Cc: kernel-team@android.com > Signed-off-by: Joel Fernandes (Google) Queued for testing and further review, thank you, Joel! Thanx, Paul > --- > This single patch superceded the patches at: > https://lore.kernel.org/patchwork/patch/1060298/ > https://lore.kernel.org/patchwork/patch/1060298/ > > include/linux/srcutree.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h > index 8af1824c46a8..9cfcc8a756ae 100644 > --- a/include/linux/srcutree.h > +++ b/include/linux/srcutree.h > @@ -123,7 +123,7 @@ struct srcu_struct { > #ifdef MODULE > # define __DEFINE_SRCU(name, is_static) \ > is_static struct srcu_struct name; \ > - struct srcu_struct *__srcu_struct_##name \ > + struct srcu_struct * const __srcu_struct_##name \ > __section("___srcu_struct_ptrs") = &name > #else > # define __DEFINE_SRCU(name, is_static) \ > -- > 2.21.0.392.gf8f6787159e-goog >