Message ID | 1668020497-13142-1-git-send-email-quic_mojha@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp512389wru; Wed, 9 Nov 2022 11:08:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5LNO89ezs5L45+W3NlL+ma7jpU9oelenXK2vdcy31nU6a0vPtcgk2QyFhmWalr/+mQM8hg X-Received: by 2002:a17:907:2995:b0:7ae:8956:ab56 with SMTP id eu21-20020a170907299500b007ae8956ab56mr4122881ejc.719.1668020920084; Wed, 09 Nov 2022 11:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668020920; cv=none; d=google.com; s=arc-20160816; b=xWFuHcFLH6s520IiRwjBAYYJf9FEQvFdyiuAMoxGVyf39Q7Mh+Sx3/RCwJ+/g77Gn1 EtPQyCATE3HSveTKFE6ceQg+NPSevgaqLE5XJM8m+ZO/oAaEsN1von7Fod64OdmNeFQ9 5XXd2QE6UimQeKfPncZM2msgHe1wNIvCGsWyebRUd2Prlr9H99vAVHA0hD3AunL97xR2 +VyQov4ve81y+VzaX2w78h3XIGNWX5Ayy/sVfhZQ4hUrFjIBZEyIdgJKcHySvVdz6JBJ GPMplTwSLP5CBSAwDSsXQt/oIT0ltHGlvQjnpEzIqjkB4xUOmTEQO05Pr9ieFViPKQjo eNKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=EzgVSr8p6AWJcO9uVFCKvzcBGMokmfaMcM0n8y9bssg=; b=RlkrGnaMGODkWp7nlk1qGSMKXFobEWCSquIM2BE2DhLRLBy3LmEnuX4Bz9WkofKFUN nXOBpKAJHddYF6yc9lbfOCBC9EMWeRIYUl8iwxYKiZfjXnRk2T+GyZeZVVVBDaRGKQZk xh462+ACAd+7Tch3KNYf25sTefNv015ejZoMON4S9Je5z55ASQQ56MxCSuLVaAC+6OXW Iqi3oQyX0LA2Cb70/aLzW9m8MF4x7VaNUb7Iie00kZti9RquTIpdsE/tg5tzINmxUYYj Hzucm1spyxNgqbnqHrMxfts3Nt2MGzuv99jfOj3Ljb1CGCp/FxFxKGt7rmIvj0/P7tT4 yHbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=bxG7spbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a50fc07000000b004573c1ae3fasi12948783edr.285.2022.11.09.11.08.15; Wed, 09 Nov 2022 11:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=bxG7spbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbiKITCM (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Wed, 9 Nov 2022 14:02:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbiKITCL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 9 Nov 2022 14:02:11 -0500 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43F94193EA for <linux-kernel@vger.kernel.org>; Wed, 9 Nov 2022 11:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1668020530; x=1699556530; h=from:to:cc:subject:date:message-id:mime-version; bh=EzgVSr8p6AWJcO9uVFCKvzcBGMokmfaMcM0n8y9bssg=; b=bxG7spbfUbhpmbfEGlW0vX/KlWrlvGeeecFtVPo5xkeuarMDDsley/Xk k5VNbeorlmAgWZK4mzYyRwryg1tctAc2aVWEc2c6VYKxFmZ0vxEFQBVAh XpiQGcwwS7T9RFdR9ASZJw+Ks5a2GKyn3Wx9RrAADs2rP/21LoPZGmZwl g=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 09 Nov 2022 11:02:09 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.45.79.139]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 11:02:09 -0800 Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Wed, 9 Nov 2022 11:02:07 -0800 From: Mukesh Ojha <quic_mojha@quicinc.com> To: <oberpar@linux.ibm.com>, <nathan@kernel.org>, <ndesaulniers@google.com>, <trix@redhat.com> CC: <linux-kernel@vger.kernel.org>, <llvm@lists.linux.dev>, Mukesh Ojha <quic_mojha@quicinc.com> Subject: [PATCH v2] gcov: clang: fix the buffer overflow issue Date: Thu, 10 Nov 2022 00:31:37 +0530 Message-ID: <1668020497-13142-1-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749046704141389918?= X-GMAIL-MSGID: =?utf-8?q?1749046704141389918?= |
Series |
[v2] gcov: clang: fix the buffer overflow issue
|
|
Commit Message
Mukesh Ojha
Nov. 9, 2022, 7:01 p.m. UTC
Currently, in clang version of gcov code when module is getting removed
gcov_info_add() incorrectly adds the sfn_ptr->counter to all the
dst->functions and it result in the kernel panic in below crash report.
Fix this by properly handling it.
[ 8.899094][ T599] Unable to handle kernel write to read-only memory at virtual address ffffff80461cc000
[ 8.899100][ T599] Mem abort info:
[ 8.899102][ T599] ESR = 0x9600004f
[ 8.899103][ T599] EC = 0x25: DABT (current EL), IL = 32 bits
[ 8.899105][ T599] SET = 0, FnV = 0
[ 8.899107][ T599] EA = 0, S1PTW = 0
[ 8.899108][ T599] FSC = 0x0f: level 3 permission fault
[ 8.899110][ T599] Data abort info:
[ 8.899111][ T599] ISV = 0, ISS = 0x0000004f
[ 8.899113][ T599] CM = 0, WnR = 1
[ 8.899114][ T599] swapper pgtable: 4k pages, 39-bit VAs, pgdp=00000000ab8de000
[ 8.899116][ T599] [ffffff80461cc000] pgd=18000009ffcde003, p4d=18000009ffcde003, pud=18000009ffcde003, pmd=18000009ffcad003, pte=00600000c61cc787
[ 8.899124][ T599] Internal error: Oops: 9600004f [#1] PREEMPT SMP
[ 8.899265][ T599] Skip md ftrace buffer dump for: 0x1609e0
....
..,
[ 8.899544][ T599] CPU: 7 PID: 599 Comm: modprobe Tainted: G S OE 5.15.41-android13-8-g38e9b1af6bce #1
[ 8.899547][ T599] Hardware name: XXX (DT)
[ 8.899549][ T599] pstate: 82400005 (Nzcv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--)
[ 8.899551][ T599] pc : gcov_info_add+0x9c/0xb8
[ 8.899557][ T599] lr : gcov_event+0x28c/0x6b8
[ 8.899559][ T599] sp : ffffffc00e733b00
[ 8.899560][ T599] x29: ffffffc00e733b00 x28: ffffffc00e733d30 x27: ffffffe8dc297470
[ 8.899563][ T599] x26: ffffffe8dc297000 x25: ffffffe8dc297000 x24: ffffffe8dc297000
[ 8.899566][ T599] x23: ffffffe8dc0a6200 x22: ffffff880f68bf20 x21: 0000000000000000
[ 8.899569][ T599] x20: ffffff880f68bf00 x19: ffffff8801babc00 x18: ffffffc00d7f9058
[ 8.899572][ T599] x17: 0000000000088793 x16: ffffff80461cbe00 x15: 9100052952800785
[ 8.899575][ T599] x14: 0000000000000200 x13: 0000000000000041 x12: 9100052952800785
[ 8.899577][ T599] x11: ffffffe8dc297000 x10: ffffffe8dc297000 x9 : ffffff80461cbc80
[ 8.899580][ T599] x8 : ffffff8801babe80 x7 : ffffffe8dc2ec000 x6 : ffffffe8dc2ed000
[ 8.899583][ T599] x5 : 000000008020001f x4 : fffffffe2006eae0 x3 : 000000008020001f
[ 8.899586][ T599] x2 : ffffff8027c49200 x1 : ffffff8801babc20 x0 : ffffff80461cb3a0
[ 8.899589][ T599] Call trace:
[ 8.899590][ T599] gcov_info_add+0x9c/0xb8
[ 8.899592][ T599] gcov_module_notifier+0xbc/0x120
[ 8.899595][ T599] blocking_notifier_call_chain+0xa0/0x11c
[ 8.899598][ T599] do_init_module+0x2a8/0x33c
[ 8.899600][ T599] load_module+0x23cc/0x261c
[ 8.899602][ T599] __arm64_sys_finit_module+0x158/0x194
[ 8.899604][ T599] invoke_syscall+0x94/0x2bc
[ 8.899607][ T599] el0_svc_common+0x1d8/0x34c
[ 8.899609][ T599] do_el0_svc+0x40/0x54
[ 8.899611][ T599] el0_svc+0x94/0x2f0
[ 8.899613][ T599] el0t_64_sync_handler+0x88/0xec
[ 8.899615][ T599] el0t_64_sync+0x1b4/0x1b8
[ 8.899618][ T599] Code: f905f56c f86e69ec f86e6a0f 8b0c01ec (f82e6a0c)
[ 8.899620][ T599] ---[ end trace ed5218e9e5b6e2e6 ]---
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
v1..v2:
- Addressed Peter O. comment.
kernel/gcov/clang.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On 09.11.2022 20:01, Mukesh Ojha wrote: > Currently, in clang version of gcov code when module is getting removed > gcov_info_add() incorrectly adds the sfn_ptr->counter to all the > dst->functions and it result in the kernel panic in below crash report. > Fix this by properly handling it. > > [ 8.899094][ T599] Unable to handle kernel write to read-only memory at virtual address ffffff80461cc000 > [ 8.899100][ T599] Mem abort info: > [ 8.899102][ T599] ESR = 0x9600004f > [ 8.899103][ T599] EC = 0x25: DABT (current EL), IL = 32 bits > [ 8.899105][ T599] SET = 0, FnV = 0 > [ 8.899107][ T599] EA = 0, S1PTW = 0 > [ 8.899108][ T599] FSC = 0x0f: level 3 permission fault > [ 8.899110][ T599] Data abort info: > [ 8.899111][ T599] ISV = 0, ISS = 0x0000004f > [ 8.899113][ T599] CM = 0, WnR = 1 > [ 8.899114][ T599] swapper pgtable: 4k pages, 39-bit VAs, pgdp=00000000ab8de000 > [ 8.899116][ T599] [ffffff80461cc000] pgd=18000009ffcde003, p4d=18000009ffcde003, pud=18000009ffcde003, pmd=18000009ffcad003, pte=00600000c61cc787 > [ 8.899124][ T599] Internal error: Oops: 9600004f [#1] PREEMPT SMP > [ 8.899265][ T599] Skip md ftrace buffer dump for: 0x1609e0 > .... > .., > [ 8.899544][ T599] CPU: 7 PID: 599 Comm: modprobe Tainted: G S OE 5.15.41-android13-8-g38e9b1af6bce #1 > [ 8.899547][ T599] Hardware name: XXX (DT) > [ 8.899549][ T599] pstate: 82400005 (Nzcv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--) > [ 8.899551][ T599] pc : gcov_info_add+0x9c/0xb8 > [ 8.899557][ T599] lr : gcov_event+0x28c/0x6b8 > [ 8.899559][ T599] sp : ffffffc00e733b00 > [ 8.899560][ T599] x29: ffffffc00e733b00 x28: ffffffc00e733d30 x27: ffffffe8dc297470 > [ 8.899563][ T599] x26: ffffffe8dc297000 x25: ffffffe8dc297000 x24: ffffffe8dc297000 > [ 8.899566][ T599] x23: ffffffe8dc0a6200 x22: ffffff880f68bf20 x21: 0000000000000000 > [ 8.899569][ T599] x20: ffffff880f68bf00 x19: ffffff8801babc00 x18: ffffffc00d7f9058 > [ 8.899572][ T599] x17: 0000000000088793 x16: ffffff80461cbe00 x15: 9100052952800785 > [ 8.899575][ T599] x14: 0000000000000200 x13: 0000000000000041 x12: 9100052952800785 > [ 8.899577][ T599] x11: ffffffe8dc297000 x10: ffffffe8dc297000 x9 : ffffff80461cbc80 > [ 8.899580][ T599] x8 : ffffff8801babe80 x7 : ffffffe8dc2ec000 x6 : ffffffe8dc2ed000 > [ 8.899583][ T599] x5 : 000000008020001f x4 : fffffffe2006eae0 x3 : 000000008020001f > [ 8.899586][ T599] x2 : ffffff8027c49200 x1 : ffffff8801babc20 x0 : ffffff80461cb3a0 > [ 8.899589][ T599] Call trace: > [ 8.899590][ T599] gcov_info_add+0x9c/0xb8 > [ 8.899592][ T599] gcov_module_notifier+0xbc/0x120 > [ 8.899595][ T599] blocking_notifier_call_chain+0xa0/0x11c > [ 8.899598][ T599] do_init_module+0x2a8/0x33c > [ 8.899600][ T599] load_module+0x23cc/0x261c > [ 8.899602][ T599] __arm64_sys_finit_module+0x158/0x194 > [ 8.899604][ T599] invoke_syscall+0x94/0x2bc > [ 8.899607][ T599] el0_svc_common+0x1d8/0x34c > [ 8.899609][ T599] do_el0_svc+0x40/0x54 > [ 8.899611][ T599] el0_svc+0x94/0x2f0 > [ 8.899613][ T599] el0t_64_sync_handler+0x88/0xec > [ 8.899615][ T599] el0t_64_sync+0x1b4/0x1b8 > [ 8.899618][ T599] Code: f905f56c f86e69ec f86e6a0f 8b0c01ec (f82e6a0c) > [ 8.899620][ T599] ---[ end trace ed5218e9e5b6e2e6 ]--- > > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com> Looks good to me! Successfully tested on s390. Fixes: e178a5beb369 ("gcov: clang support") Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Tested-by: Peter Oberparleiter <oberpar@linux.ibm.com> And I'm not sure if this is strictly needed, but we could also add: Cc: <stable@vger.kernel.org> # 5.2+ @Andrew: could you pick this up via your tree? > --- > v1..v2: > - Addressed Peter O. comment. > > kernel/gcov/clang.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/gcov/clang.c b/kernel/gcov/clang.c > index cbb0bed..7670a81 100644 > --- a/kernel/gcov/clang.c > +++ b/kernel/gcov/clang.c > @@ -280,6 +280,8 @@ void gcov_info_add(struct gcov_info *dst, struct gcov_info *src) > > for (i = 0; i < sfn_ptr->num_counters; i++) > dfn_ptr->counters[i] += sfn_ptr->counters[i]; > + > + sfn_ptr = list_next_entry(sfn_ptr, head); > } > } >
diff --git a/kernel/gcov/clang.c b/kernel/gcov/clang.c index cbb0bed..7670a81 100644 --- a/kernel/gcov/clang.c +++ b/kernel/gcov/clang.c @@ -280,6 +280,8 @@ void gcov_info_add(struct gcov_info *dst, struct gcov_info *src) for (i = 0; i < sfn_ptr->num_counters; i++) dfn_ptr->counters[i] += sfn_ptr->counters[i]; + + sfn_ptr = list_next_entry(sfn_ptr, head); } }