Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1255042pxa; Thu, 20 Aug 2020 06:53:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0GdEWnDVgjSUtf+4cS/QmMHyaut8oQBagj0o03KlUhM/D3tYLHwyh8KVVOe1iSonODoSQ X-Received: by 2002:a17:906:b6d5:: with SMTP id ec21mr3247678ejb.396.1597931597617; Thu, 20 Aug 2020 06:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931597; cv=none; d=google.com; s=arc-20160816; b=XRpXf32W8F7ytL8R67F3RNgGd7GL4ClI2HDGIMAGuVvw5/WGizSoGDWrVnogVlmz+0 6WUX8yctoyfRsYrg3YZa2Ja1y2eNWeuyQ0ghR3D9MIayrdbzNO38B6uwMo34LRu3Icsy ZVMGHMaEGrk9QyReoO+7Nx89rq6vzRXDlf5Q7VgD+VNev2AdWbaSP1+upxClb3bEWiBu EZrEDB1A32oEzcBYinu2aW/G0tf4mM1vBxyuLPHZtvzGEEHZWX1VzFE7eUc3lSCn5ily uEhfaD4LjHtQjWt/h8di3sJlH+IlcmRq52/buXg7kCXDIoQKt0uB71zJC1ZpIevbY38M 66Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=125zNdEP1/2Ch+iAvi54wNk5onOg1SVxEwnh16PoKZk=; b=tQDkH+BgbxTgafstpBdEOeshvGNFKq9SHvR8CFv8I3a8RztQmtT1AFBHj9T4OtSCsF 2zV92Ccept1Zaw95c8new7/HcoeLY7VPIxdWkpoIhgaDz/ekOfaUVKIoAvbiviwoz0FZ IjDBPllRh3GJIMlf1/ha5+5n+qJLgNmwPd6JdYMbudVqelzMv34GLnYpggXZ9woEaulj 0bcaMithcO/1ktL7DFLayfZE2jy/AUUhkcga4hXdjMJEetrjtgk1Bd9gkNQSTSp2xOUD oI4IVffzcxl/IFMmNYeOng5voLg1SBq85vzIR5lTNdEp4TS6n0lh1vDxX5Ay4CyEpHqv mwLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZEReOPI1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si1248294ejo.605.2020.08.20.06.52.53; Thu, 20 Aug 2020 06:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZEReOPI1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729027AbgHTNtf (ORCPT + 99 others); Thu, 20 Aug 2020 09:49:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727990AbgHTJ1d (ORCPT ); Thu, 20 Aug 2020 05:27:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D342522D03; Thu, 20 Aug 2020 09:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915653; bh=kPzDIg3ULW4/+BsQ5fmrDHG5O+ojWJwe6pzGFhBe8zM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEReOPI1u87GUlGNXh03o8mOAol6kXegZTE79Ny65kd4vjMy/1fNIoi1dHfzuYkGY vJ7EdzDIZLTpOL+BD8N5spUCX4/PAAJEWOBP6dHtFvfqLZY5P1MveWXB1IJShUlqd0 kbGn3NYdNBD02PiNAqJZJyLM3DQFXMz1n+zbsZt4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chengming Zhou , Muchun Song , "Steven Rostedt (VMware)" Subject: [PATCH 5.8 088/232] ftrace: Setup correct FTRACE_FL_REGS flags for module Date: Thu, 20 Aug 2020 11:18:59 +0200 Message-Id: <20200820091617.088880000@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chengming Zhou commit 8a224ffb3f52b0027f6b7279854c71a31c48fc97 upstream. When module loaded and enabled, we will use __ftrace_replace_code for module if any ftrace_ops referenced it found. But we will get wrong ftrace_addr for module rec in ftrace_get_addr_new, because rec->flags has not been setup correctly. It can cause the callback function of a ftrace_ops has FTRACE_OPS_FL_SAVE_REGS to be called with pt_regs set to NULL. So setup correct FTRACE_FL_REGS flags for rec when we call referenced_filters to find ftrace_ops references it. Link: https://lkml.kernel.org/r/20200728180554.65203-1-zhouchengming@bytedance.com Cc: stable@vger.kernel.org Fixes: 8c4f3c3fa9681 ("ftrace: Check module functions being traced on reload") Signed-off-by: Chengming Zhou Signed-off-by: Muchun Song Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6187,8 +6187,11 @@ static int referenced_filters(struct dyn int cnt = 0; for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { - if (ops_references_rec(ops, rec)) - cnt++; + if (ops_references_rec(ops, rec)) { + cnt++; + if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) + rec->flags |= FTRACE_FL_REGS; + } } return cnt; @@ -6367,8 +6370,8 @@ void ftrace_module_enable(struct module if (ftrace_start_up) cnt += referenced_filters(rec); - /* This clears FTRACE_FL_DISABLED */ - rec->flags = cnt; + rec->flags &= ~FTRACE_FL_DISABLED; + rec->flags += cnt; if (ftrace_start_up && cnt) { int failed = __ftrace_replace_code(rec, 1);