Received: by 10.192.165.148 with SMTP id m20csp355788imm; Wed, 2 May 2018 01:14:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpQavZxfCszuHc1r09lx6bxtvs3KEDEIYp81zXzwIvUKyN1gw3VHD/kQ3Ns8c5f2m24zHmu X-Received: by 2002:a17:902:7241:: with SMTP id c1-v6mr19294027pll.217.1525248853362; Wed, 02 May 2018 01:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525248853; cv=none; d=google.com; s=arc-20160816; b=EOxVNH72Lj64rh9J6Eec+JoXTGwIKydNh7KlTr2OswEe5tEtuwNZ+1f7bt9XqP2BAO O1w9ub/hUkoZgwTBx8OTBQlqUIln/5f+SsaCkmtQRQKw+yM6vr6uk72Y22p8DwpqF/Ay cuopqRmzumNo/3ZwO7V5MHfvHS/s3NFgWx5z7Um5BVkB8gSDHKfqc+Eq0cS5i6tgPFe6 adLpHcRYQ35TMnaOvdmc6dwfsQiwVwh00lnnW8ESoPlIiewBd/ieWkXb9shjI5Ic+HLi YckrDEHPYImLCqYbTX8Pee36BbnrlY2TONqCLDGvfVJPaQElHJN5i0zXZQkAUNT4gm7h vOSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :organization:from:references:cc:to:subject :arc-authentication-results; bh=Ru5N++FnKO58qqtDF0YcEhXpsVrfKxqujLzqjjC/GSY=; b=tD1ZZyzrUkM0mzrafEhwzJ8Muzo8dsBV3qLxtZSidaDkw9pdX0NyKoGyfHV39CB81y YeoU5lS+9zSD1O0RGah9LBOm07M8Gs73FoYCqZnbSq6f2+SD8ACclapcIYpVOZnpL21T RjRIsL/JS3iI7kzJmoW3Coq3+51rn9hTEEUAoh8K4HB72jv9O6XJy+nZW5WC7UtDQZIA xKSmxGHWqxzLt25FsCIAvwSegi+7sVKwPGk8+q3KdyRUtN65cGRLmTvG7e+DY94jCKl2 ZV2FNoVCEu6d81dTx1Fmbhk2PxgotQiwchakZuMm1ypzTABbeK2TwQEumqDdFAl5CmUI vdiw== 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 j6si11091000pfc.351.2018.05.02.01.13.58; Wed, 02 May 2018 01:14:13 -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 S1751354AbeEBINt (ORCPT + 99 others); Wed, 2 May 2018 04:13:49 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49092 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751240AbeEBINq (ORCPT ); Wed, 2 May 2018 04:13:46 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w427sJAx134808 for ; Wed, 2 May 2018 04:13:45 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2hq6syek3w-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 02 May 2018 04:13:45 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 May 2018 09:13:43 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 2 May 2018 09:13:39 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w428Dcmt197100; Wed, 2 May 2018 08:13:38 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E72342049; Wed, 2 May 2018 09:04:51 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8089142041; Wed, 2 May 2018 09:04:50 +0100 (BST) Received: from oc3784624756.ibm.com (unknown [9.152.212.113]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 2 May 2018 09:04:50 +0100 (BST) Subject: Re: [PATCH v3] module: Fix display of wrong module .text address To: Kees Cook Cc: Jessica Yu , Linus Torvalds , LKML , Christian Borntraeger , Martin Schwidefsky , brueckner@linux.vnet.ibm.com, Heiko Carstens , Peter Zijlstra , Arnaldo Carvalho de Melo , "Tobin C. Harding" , "# 3.4.x" References: <20180418071436.21392-1-tmricht@linux.ibm.com> From: Thomas-Mich Richter Organization: IBM LTC Date: Wed, 2 May 2018 10:13:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 18050208-0020-0000-0000-00000418098D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050208-0021-0000-0000-000042AD2441 Message-Id: <024d902c-54d7-f91e-4d71-57da4b15b3f9@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-02_03:,, 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805020074 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/02/2018 04:20 AM, Kees Cook wrote: > On Wed, Apr 18, 2018 at 12:14 AM, Thomas Richter wrote: >> Reading file /proc/modules shows the correct address: >> [root@s35lp76 ~]# cat /proc/modules | egrep '^qeth_l2' >> qeth_l2 94208 1 - Live 0x000003ff80401000 >> >> and reading file /sys/module/qeth_l2/sections/.text >> [root@s35lp76 ~]# cat /sys/module/qeth_l2/sections/.text >> 0x0000000018ea8363 >> displays a random address. >> >> This breaks the perf tool which uses this address on s390 >> to calculate start of .text section in memory. >> >> Fix this by printing the correct (unhashed) address. >> >> Thanks to Jessica Yu for helping on this. >> >> Fixes: ef0010a30935 ("vsprintf: don't use 'restricted_pointer()' when not restricting") >> Cc: # v4.15+ >> Suggested-by: Linus Torvalds >> Signed-off-by: Thomas Richter >> Cc: Jessica Yu >> --- >> kernel/module.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/kernel/module.c b/kernel/module.c >> index a6e43a5806a1..40b42000bd80 100644 >> --- a/kernel/module.c >> +++ b/kernel/module.c >> @@ -1472,7 +1472,8 @@ static ssize_t module_sect_show(struct module_attribute *mattr, >> { >> struct module_sect_attr *sattr = >> container_of(mattr, struct module_sect_attr, mattr); >> - return sprintf(buf, "0x%pK\n", (void *)sattr->address); >> + return sprintf(buf, "0x%px\n", kptr_restrict < 2 ? >> + (void *)sattr->address : NULL); > > Errr... this looks reversed to me. > > I would expect: "kptr_restrict < 2 ? NULL : (void *)sattr->address" > > -Kees > I am confused: In my patch, if kptr_restrict == 2 it prints NULL, which kptr_restrict being 0 or 1 it prints the address. In your comment if kptr_restrict == 2 it prints the address, which kptr_restrict being 0 or 1 it prints NULL. Looking into Documentation/sysctl/kernel.txt: When kptr_restrict is set to (2), kernel pointers printed using %pK will be replaced with 0's regardless of privileges. With my patch, setting kptr_restrict to 0 or 1 prints the real kernel address (format %px, unmodified address according to Documentation/printk-formats.txt). I have tested this on s390 (which is the only arch using file /sys/module//sections/.text) in the perf tool. root@s8360047 ~]# sysctl kernel.kptr_restrict kernel.kptr_restrict = 0 [root@s8360047 ~]# cat /proc/modules | egrep '^qeth_l2' qeth_l2 102400 1 - Live 0x000003ff8034d000 [root@s8360047 ~]# cat /sys/module/qeth_l2/sections/.text 0x000003ff8034da68 [root@s8360047 ~]# sysctl -w kernel.kptr_restrict=2 kernel.kptr_restrict = 2 [root@s8360047 ~]# cat /proc/modules | egrep '^qeth_l2' qeth_l2 102400 1 - Live 0x0000000000000000 [root@s8360047 ~]# cat /sys/module/qeth_l2/sections/.text 0x0000000000000000 [root@s8360047 ~]# uname -a Linux s8360047 4.17.0-rc3m-perf+ #6 SMP PREEMPT Wed May 2 10:02:38 CEST 2018 s390x s390x s390x GNU/Linux [root@s8360047 ~]# Hope this helps. -- Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294