Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp620404lqm; Wed, 1 May 2024 10:24:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVu5HvtZaBZLD/T5Tu+WoQojoazgq/U8EN67Fqw4nCsEPH0BA1XYtKSbmNiCcvezk22o/Bhfv4vWedDoPdHEpZQcbax8PbG6hQ1Mh8CiA== X-Google-Smtp-Source: AGHT+IFUCwPJ78w0Xq0IcVegClkGlnAz+2GIOEasKNzMDLfmiyXArnms+lGn4dYuYziGPVlXoOU1 X-Received: by 2002:a50:d781:0:b0:56e:418:5559 with SMTP id w1-20020a50d781000000b0056e04185559mr2027390edi.3.1714584266401; Wed, 01 May 2024 10:24:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714584266; cv=pass; d=google.com; s=arc-20160816; b=aJe5G4rkqTwDPeD5tTkJtVGeHlJuXq/Pp5LAAQ2WJe/DYMT4kSYJyUiJ9wOIlj5LYi QTot78vu4LCskfgjM09DJR1aZb65Jr+3BV9L19j6rAhYwoeFx4L/crE/OQBt6KmDe0+D 6dWl9LeX15dj/P//C/QcqAszP1OSZK5buZPZ7iBFfWm66/zJyBc/I6lbHhYyx+bXNbF2 xfwpbFBCzFQKGiQto1dfFb74V4QLdgI6r0eFNfjxPpaDZxSBOVsepsmCBmESEMbU+MCX pFq8bJd9nLSsghMVDNnIPm/fRom24vswkElv5nKTrFKx1pLAjO0NRuXt7cJaPR42CFHn rOOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=1xXhyZAtUC4x8RQ9tzj66ybBURcXZ3pJBjmcJtKEaKI=; fh=TjqclKyv1FBKnILBxj6s7SBwjCTjLN2QLsuU0ADGqow=; b=zKLoqnshOlgZD1khfUxAz2eYaYjrf53l7KpEGdmlnxWVcBQxagUcPCikCDfTxx6eCN d9m3irEnVWuf/9VN1xSWTHB6ioB0QlRo3Xl6U1+jmW+neuzWMwnn9FM7hqMKmG6SHynw I82FWRAbX69Pj9zpxAEvx/ntpth6VdfmOaSKgIatIX9VABw3BreOG44MiTl7G2UyYlKU aWAOCflea3IVGkiClV1v09mW0IzxdiqAZg5O+zoh2LFmvRRuHvKQxm8VfYEcd4dQJicc TfG9V0Km/N7ekwX3EukQEsgDtqsEuPfuj8lonWzwYUG+a0IilxW6s0MD6rga5pLbn5Uy iAKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-165641-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165641-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l17-20020aa7d951000000b00572af6b2cdbsi681932eds.679.2024.05.01.10.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 10:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165641-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-165641-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165641-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 261231F21C40 for ; Wed, 1 May 2024 17:24:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17EF91B7F4; Wed, 1 May 2024 17:24:19 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8150F18C08; Wed, 1 May 2024 17:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714584258; cv=none; b=eymU2cdFcUW6R7PQGAqIaapIvAu4JlA1QakKZXciA4VkDYkwqZUeOBpOXDfvC4NaEJems3lasXlLFdRvPZl+aTfbynTyoecuS2p3piS0GVMthR2/8Ti4MyqJh0jCSI4TnufdxwFOhseQBrIu4y7fHRkFzGpHSg5eZKlkVx1xze8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714584258; c=relaxed/simple; bh=l3KI1mpm3TLzcA+uIN1rJJ4uvAsCdYr6Lv0kEgC1Fmg=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nlSQAI+PHahM+RKuB+SFuYxRvbO5soPogUOmPCsEbYCZxWGM36Bt71EoETadFDEdwzDmcS1Vaw6QMU1G19hVL7W7K7fkF4b+U2uziKBYrcuNaIgkD4CHmYjBQIyaKtuUbeNSDgqWm+aWnkjjPAQqC6KOT9rpThNSm5AFPs+s1ms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 622E2C072AA; Wed, 1 May 2024 17:24:14 +0000 (UTC) Date: Wed, 1 May 2024 13:24:58 -0400 From: Steven Rostedt To: Stephen Brennan Cc: Masami Hiramatsu , Mark Rutland , Guo Ren , Huacai Chen , WANG Xuerui , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org Subject: Re: [PATCH v3] kprobe/ftrace: bail out if ftrace was killed Message-ID: <20240501132458.3ea28f6b@gandalf.local.home> In-Reply-To: <20240501162956.229427-1-stephen.s.brennan@oracle.com> References: <20240501162956.229427-1-stephen.s.brennan@oracle.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 1 May 2024 09:29:56 -0700 Stephen Brennan wrote: > If an error happens in ftrace, ftrace_kill() will prevent disarming > kprobes. Eventually, the ftrace_ops associated with the kprobes will be > freed, yet the kprobes will still be active, and when triggered, they > will use the freed memory, likely resulting in a page fault and panic. > > This behavior can be reproduced quite easily, by creating a kprobe and > then triggering a ftrace_kill(). For simplicity, we can simulate an > ftrace error with a kernel module like [1]: > > [1]: https://github.com/brenns10/kernel_stuff/tree/master/ftrace_killer > > sudo perf probe --add commit_creds > sudo perf trace -e probe:commit_creds > # In another terminal > make > sudo insmod ftrace_killer.ko # calls ftrace_kill(), simulating bug > # Back to perf terminal > # ctrl-c > sudo perf probe --del commit_creds > > After a short period, a page fault and panic would occur as the kprobe > continues to execute and uses the freed ftrace_ops. While ftrace_kill() > is supposed to be used only in extreme circumstances, it is invoked in > FTRACE_WARN_ON() and so there are many places where an unexpected bug > could be triggered, yet the system may continue operating, possibly > without the administrator noticing. If ftrace_kill() does not panic the > system, then we should do everything we can to continue operating, > rather than leave a ticking time bomb. > > Signed-off-by: Stephen Brennan > --- > Changes in v3: > Don't expose ftrace_is_dead(). Create a "kprobe_ftrace_disabled" > variable and check it directly in the kprobe handlers. Reviewed-by: Steven Rostedt (Google) Thanks, -- Steve