Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4575646pxt; Wed, 11 Aug 2021 09:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJrOnLLJL3ALgeN8JBpwd8kdVeL7xkaAMDxA6xSC9t/daOVZFaqT1vVfASKx5vSmPTiTOR X-Received: by 2002:a05:6638:3889:: with SMTP id b9mr32471078jav.83.1628697795928; Wed, 11 Aug 2021 09:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628697795; cv=none; d=google.com; s=arc-20160816; b=SZozRVOo2z73cbNd4C5pycFECVLSZ2vp4JDidioKzEeHlObMyAJAftjrgqYXtDOjSD iffOowDTdhsmAorpBpVTE1JOAThplvUWOZms8AHgvyT2vwBkHxnLy87rYsIrlVthwZYE rW4hkPF0yIbWeBa3DevYL8nlrC75k1e2juYXfNr02k5vM/p3P7N7FkFkEpIAetKVEbqf R/4JH6+qMLtxqyAo03Hv2AUFvWbfGwpcUfsSxHgp+0zMxKydP82xYnTrvwQDJaZcdmXI dykwg4DR+7DbGMnjOUpvmJYogW9zp9R9yoz1R5TABmkvos6bYCX1IZ4HkqD4eNbu0AV+ lsOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=FR7vwnV0JqhLBRywr8xKMr6WEzZDJpWzAymy3dGfNb0=; b=t8AJ7iEDm+ragH6XS2MAPYwWk77WztE2Nt2TmeY26mySBKilfcF14ZSjQonbr6rp+y Boo9pPi13Q1q96SlDGyFyUmuj+nmTUQTW/1y2ShGrOLU2J16SKpFLghkGyEOlcl0LUkf mQen+hKCLrExbwkdYj0s3amQXNV7pUpjWLMq10IoNa6794OsjYU06opDyVRpryRphzdT D8/OnSdto4226Af2NrL48J71lq8tRnt02r/AGR6R1Fv5rNCHFkUMnsfnF+4uH0K+zQM6 h3P37Iuzy/yoa6zkUveq1w732m9HTSjCBMdHvLbarTafDB9ZD8jGHTkRrcHIEocU9yXj hcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@quicinc.com header.s=qcdkim header.b=rkId31qk; 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=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si24916747ilo.50.2021.08.11.09.02.55; Wed, 11 Aug 2021 09:03:15 -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=fail header.i=@quicinc.com header.s=qcdkim header.b=rkId31qk; 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=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233442AbhHKQAV (ORCPT + 99 others); Wed, 11 Aug 2021 12:00:21 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:7412 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232847AbhHKQAU (ORCPT ); Wed, 11 Aug 2021 12:00:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1628697597; x=1660233597; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Q6bTaAzqKCmfR9183c3CDW98qIeaLOQ4+KwxcaEL7Ds=; b=rkId31qkMxh0/yB6MuQovQH6Bc66jIxU1UTFK4Yb5Wl2aW+INFkgwmvx FRi1RBoT0mi9I9TUvp6yPBkcFvI3FJHHMBhV9I+RTyWJlOolAktMi8l2F 9Jw2nMwRESuFyvqL0q8neG/idoDnXtZMdgt6qy7n/kxFKgEQ+c2FkbT16 Q=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-02.qualcomm.com with ESMTP; 11 Aug 2021 08:59:56 -0700 X-QCInternal: smtphost Received: from nasanexm03e.na.qualcomm.com ([10.85.0.48]) by ironmsg01-sd.qualcomm.com with ESMTP/TLS/AES256-SHA; 11 Aug 2021 08:59:56 -0700 Received: from hu-eberman-lv.qualcomm.com (10.80.80.8) by nasanexm03e.na.qualcomm.com (10.85.0.48) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 11 Aug 2021 08:59:55 -0700 From: Elliot Berman To: Sami Tolvanen , Kees Cook CC: Elliot Berman , , Jinlong Mao Subject: [PATCH 1/1] cfi: Use rcu_read_{un}lock_sched_notrace Date: Wed, 11 Aug 2021 08:59:14 -0700 Message-ID: <20210811155914.19550-1-quic_eberman@quicinc.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanexm03f.na.qualcomm.com (10.85.0.47) To nasanexm03e.na.qualcomm.com (10.85.0.48) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If rcu_read_lock_sched tracing is enabled, the tracing subsystem can perform a jump which needs to be checked by CFI. For example, stm_ftrace source is enabled as a module and hooks into enabled ftrace events. This can cause an recursive loop where find_shadow_check_fn -> rcu_read_lock_sched -> (call to stm_ftrace generates cfi slowpath) -> find_shadow_check_fn -> rcu_read_lock_sched -> ... To avoid the recursion, either the ftrace codes needs to be marked with __no_cfi or CFI should not trace. Use the "_notrace" in CFI to avoid tracing so that CFI can guard ftrace. Signed-off-by: Elliot Berman --- kernel/cfi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/cfi.c b/kernel/cfi.c index e17a56639766..9594cfd1cf2c 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -248,9 +248,9 @@ static inline cfi_check_fn find_shadow_check_fn(unsigned long ptr) { cfi_check_fn fn; - rcu_read_lock_sched(); + rcu_read_lock_sched_notrace(); fn = ptr_to_check_fn(rcu_dereference_sched(cfi_shadow), ptr); - rcu_read_unlock_sched(); + rcu_read_unlock_sched_notrace(); return fn; } @@ -269,11 +269,11 @@ static inline cfi_check_fn find_module_check_fn(unsigned long ptr) cfi_check_fn fn = NULL; struct module *mod; - rcu_read_lock_sched(); + rcu_read_lock_sched_notrace(); mod = __module_address(ptr); if (mod) fn = mod->cfi_check; - rcu_read_unlock_sched(); + rcu_read_unlock_sched_notrace(); return fn; } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project