From patchwork Tue Jan 23 00:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 190653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp69003dyi; Mon, 22 Jan 2024 17:51:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfX6WmtaZ4Rzse99dtN/zy5nYXgFOe7VHzHW/zMzZvwvyWCoqSo4lJhA+b046U4bkJVQ6o X-Received: by 2002:a05:6a20:6594:b0:199:87dc:4f0a with SMTP id p20-20020a056a20659400b0019987dc4f0amr5092880pzh.95.1705974674302; Mon, 22 Jan 2024 17:51:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705974674; cv=pass; d=google.com; s=arc-20160816; b=XT3OES1VAlfoJIJgDPoQ7mP21NqD3y93Rwf4HPXnY9Ng6Sf3IC2lTrGnBknVd7TqxJ FtI09+f09x4cDmhSlWJIohzmoJRCMc8thwz3U61OqhLpZasTOT63lIdf+wFJ3B/JUXrg YI0r+imdAcLnvuhftg4kFJmRw0VihcwVuJtMVNTAur/wHhkD3Irzp9SfIaWl39ZIRv0t y21ynXtVST0mV5gk8/kaEZQyxg4D2aakMpevOuL8XcyBUbWsHxNn59xvd1J4KDbS0jgY dA2NZxCXfJdSAjDOMkHqNKmx9xJ1mTvUf1QFQtml7psGik2OC/LG3JZok8BaBcaqK9KM gHrA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=UvBYWd8ctJzu4aNLGaHJim5X1ADrbbpkxcKvf49QESc=; fh=b8CeGSJbuRvrl4T/63td3Z/6zbAw+O63c3cHs4zQBiU=; b=cFOL2P1loMeUdkPmlwiITJOz4a/MJfhXsJ265bsHubEGqBrwmFYAlKDfTRNEka9aGx pPe88kUqq/wNdjmeWRFgujIeA0shZgrt7X+RuOhAZ7KVU8i4SK2PvFO082X0TKnoDEQA QaI7bgeZPJCc8N2CljBfYqxF1hfYnZJZWsGl/K4hYZ7q9i5oOFmdZQUIS2YCnnF+Bjyp DpzHbvwuS+VWd9EHX03qJSDFC4IYuiG/nNGkwQQDH/L6/t2eklEXLvn6WDGlIs6w8W77 l7aqomFMQFmB/HWXRhijI4J7tqlznKnSmn4AJ084HeQbTlf+UtlbedWixFYzfR03qQtA qmyw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P+Mnl9nA; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34555-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ga8-20020a17090b038800b0028d871d1281si9081813pjb.34.2024.01.22.17.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 17:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=P+Mnl9nA; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34555-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1284929BFAB for ; Tue, 23 Jan 2024 01:51:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D30C1129A9B; Tue, 23 Jan 2024 00:50:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P+Mnl9nA" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B4601292FC for ; Tue, 23 Jan 2024 00:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971012; cv=none; b=ppih/Mx0nb1TkHq6HOwr7ptVNEsHGrrKjul9xz4sLdK7T41Diju7UtD3DVYlPMdC5pmHECyOMcEUbieWsysPb2YaWWvAFGJTZKK4JtBvAi9gysDJGc3U999J6zAILOIpugE70aDOwW5L8H+FA1gLVy26LmLIsk2xfHhnx7PgeWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971012; c=relaxed/simple; bh=z1zpB2qqR0IBjDwv2KLwS6K9nwmw0h+fbzHKVoKHyN4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=diNpI01qGNLkls0vA+VN6c8hAIYRwrymYtzPoILk2/YTpHOwDt6WBpXvGJH64SwEeGh5j+gW//9Qt/waI7UwstML7n8Ojy52AE72KoPES+P5AAYVnZL7XHKKPEmE8bwdLyCS8+x/4SLTb3H+ubf6iKPvX7SdB33MpVRlc3LZKDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=P+Mnl9nA; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6dc6f47302bso628151b3a.1 for ; Mon, 22 Jan 2024 16:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705971010; x=1706575810; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UvBYWd8ctJzu4aNLGaHJim5X1ADrbbpkxcKvf49QESc=; b=P+Mnl9nAFonmD0jfc0w3dDtc+L9WYZDzUQOMtrI5Bb8GIfQMI9LK+wrQGNuV6sh1Wi /r87+UOFOL8xwMTjE/2R1307nDbeQzPT4Y+iunsBP4AuAYZpIXtX1bb66RDDmJBZzclz CM+SOE7ZqmkFWTZ6hKJN331GHw5GrGKWjJCIk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705971010; x=1706575810; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UvBYWd8ctJzu4aNLGaHJim5X1ADrbbpkxcKvf49QESc=; b=lmrGvJ67C3elruoyXh2VJgGxt14zvMz3oAHRkLUCjstYdqQLmqNsBw0MM44EvHUhPb k5fVZ2cV2EaF5b//MY5zqxb9eC60kic+bNfccy+HTbZ2Au3FKzxVswydVzHqV3U9moEM GL10Ty1pj/yCa4s/iyilqNif4DcnUMCarPjfH4O9cYk5LB/+qNGSWrZteUt8L8lTarjF qsPGg6RvhEKEHo9oce3bcvY+TD5XjJ1tRL2VXvyS/V78nPUTYooXuONDx5yrT+DjdQcD CseI5R2lst9ImJCvxplhldzB3gzQaTdXIub1hVwgftlYhxRrMf8lzppUjpexk4y3HixW t3Eg== X-Gm-Message-State: AOJu0YwCCvgPD4nrB3XRDx55k0MXD0GuiwsGDwolwD/0b93e7kTTnl4X KRu8YQfJLjqzy0Ca2zEztDOQE/QZkzCrbWVdGsILHVoJSAWzLhBEhtg7z6eLqg== X-Received: by 2002:a05:6a00:2e2a:b0:6db:b355:892d with SMTP id fc42-20020a056a002e2a00b006dbb355892dmr7718013pfb.2.1705971009946; Mon, 22 Jan 2024 16:50:09 -0800 (PST) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:6e04:285a:ab4d:3428]) by smtp.gmail.com with ESMTPSA id y5-20020aa79e05000000b006d9ef76732esm10190912pfq.213.2024.01.22.16.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:50:09 -0800 (PST) From: Douglas Anderson To: Kees Cook Cc: Arnd Bergmann , Greg Kroah-Hartman , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] lkdtm: Make lkdtm_do_action() return to avoid tail call optimization Date: Mon, 22 Jan 2024 16:49:34 -0800 Message-ID: <20240122164935.1.I345e485f36babad76370c59659a706723750d950@changeid> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788844099801356235 X-GMAIL-MSGID: 1788844099801356235 The comments for lkdtm_do_action() explicitly call out that it shouldn't be inlined because we want it to show up in stack crawls. However, at least with some compilers / options it's still vanishing due to tail call optimization. Let's add a return value to the function to make it harder for the compiler to do tail call optimization here. Now that we have a return value, we can actually use it in the callers, which is a minor improvement in the code. Signed-off-by: Douglas Anderson --- drivers/misc/lkdtm/core.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c index 0772e4a4757e..5732fd59a227 100644 --- a/drivers/misc/lkdtm/core.c +++ b/drivers/misc/lkdtm/core.c @@ -153,12 +153,17 @@ static const struct crashtype *find_crashtype(const char *name) /* * This is forced noinline just so it distinctly shows up in the stackdump * which makes validation of expected lkdtm crashes easier. + * + * NOTE: having a valid return value helps prevent the compiler from doing + * tail call optimizations and taking this out of the stack trace. */ -static noinline void lkdtm_do_action(const struct crashtype *crashtype) +static noinline int lkdtm_do_action(const struct crashtype *crashtype) { if (WARN_ON(!crashtype || !crashtype->func)) - return; + return -EINVAL; crashtype->func(); + + return 0; } static int lkdtm_register_cpoint(struct crashpoint *crashpoint, @@ -167,10 +172,8 @@ static int lkdtm_register_cpoint(struct crashpoint *crashpoint, int ret; /* If this doesn't have a symbol, just call immediately. */ - if (!crashpoint->kprobe.symbol_name) { - lkdtm_do_action(crashtype); - return 0; - } + if (!crashpoint->kprobe.symbol_name) + return lkdtm_do_action(crashtype); if (lkdtm_kprobe != NULL) unregister_kprobe(lkdtm_kprobe); @@ -216,7 +219,7 @@ static int lkdtm_kprobe_handler(struct kprobe *kp, struct pt_regs *regs) spin_unlock_irqrestore(&crash_count_lock, flags); if (do_it) - lkdtm_do_action(lkdtm_crashtype); + return lkdtm_do_action(lkdtm_crashtype); return 0; } @@ -303,6 +306,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf, { const struct crashtype *crashtype; char *buf; + int err; if (count >= PAGE_SIZE) return -EINVAL; @@ -326,9 +330,11 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf, return -EINVAL; pr_info("Performing direct entry %s\n", crashtype->name); - lkdtm_do_action(crashtype); + err = lkdtm_do_action(crashtype); *off += count; + if (err) + return err; return count; } From patchwork Tue Jan 23 00:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 190654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp69089dyi; Mon, 22 Jan 2024 17:51:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuEng0P//dN6K/yAIprh4sn8Wrls9ICiQc887EhOvNPdlExeYX0qCAxT+UgIZpnx1AqdfX X-Received: by 2002:aca:1b01:0:b0:3bd:a2fd:cdd0 with SMTP id b1-20020aca1b01000000b003bda2fdcdd0mr4706754oib.63.1705974689463; Mon, 22 Jan 2024 17:51:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705974689; cv=pass; d=google.com; s=arc-20160816; b=zNxOklEXVrUs4Whj+YAdGetVks4Fk5mojz0IrV0tH1h9qn4xJzzWm9B4vTETmgcgMk vsgN9ZdoLMOzFyPWmtGZCiCyw/TIc2HZBRarCAo8jVii80U+o29CZzaqrUzTAvaSfse4 prp7Y8jHZ8yYWYgCAV+xjkZaDVUrEIUsHd4kQZ5q4tBADIpWeCl/IJlRPpt1bNyEEQB0 rcrGxjdxtzezDb9anKiDNjdSRecDaXamk5/VG20UkXiVBxFLyMhC45BsC2ddOeAVZKzB r/o1qnJuX05A3mbQ/yobUl1HAI/psooHubA/Yh5Zd2aUil+umJ/W9dwSNql9GO4zOgHY VpyA== 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 :date:subject:cc:to:from:dkim-signature; bh=gcI3IZKj7A7EP+PZYroCXqSoSDvWd+f5jhzLQV1RU3E=; fh=b8CeGSJbuRvrl4T/63td3Z/6zbAw+O63c3cHs4zQBiU=; b=qLh+QFcABLaVWp8x4Z9TLFNrMchLMJAGXAW8QLP6g/LOttOfJvaKcDZoGPWVLnid9N XXZJmYtuDbZezSJLlNpkJks/JodaJHL7ms/lPP8qh5L3pQZ/LKoZu9Ass+UwGxQ2d6zB gZeawiebH9B5iP8rVEBbjlszdoR/49+SZp7rQPk1s0ZD4LJFSPAdyc2bFsvXZgff7n4a lS3baZ1yGpV8htj3yDUqezfCOOEPJKPnoPgIau34KNsgSZPBlK0040u6qEFCQmVBY/Vm /PhU8ddnLFRqS1tXnjwwV7nG3PmgmcFoncXwsdeQE6bvgGgw4JXMfiDSSwmAQPRl5yWr j3yA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PqnwYr0+; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34556-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34556-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g4-20020a056a0023c400b006d9b31a5243si11260614pfc.350.2024.01.22.17.51.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 17:51:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34556-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PqnwYr0+; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34556-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34556-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1341229C002 for ; Tue, 23 Jan 2024 01:51:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C75D612A157; Tue, 23 Jan 2024 00:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="PqnwYr0+" Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B82CE129A86 for ; Tue, 23 Jan 2024 00:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971014; cv=none; b=tpLw/nlkpE0l5bjBefeDtAmpbgdCND2cjsXN0FA7w9eiubqy5KIjafgX29zMVNj+9F8Q2CdOiRLZfy7l2ibQ02+lXJINBKDjhmoYTs+SG45zKLHg3F9ragDfXb+h/wnz6eepNsHMML7JGvC6tEIpkEV7XaUzmKgzZeERU86zvFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705971014; c=relaxed/simple; bh=sL4bxvnrXWPZkUyOQMK2D+DPl/Ah5bGRWYZLBAO9F2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScxZ0d7xMbztFPhbuvQBOMbD3ubwj5pWEwgEjlC0ouK0CpS509Zs+0hy+ctKVZQs3nJa908ad/A/hUcOBptioTb+dzdNYuxZDWM6MNSgrFl//g1o7tDblbFOkHRtNlht+67CVzlMlmAVj5SfR7MWQHlZFb1meuLRSTzxLBQ8UME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=PqnwYr0+; arc=none smtp.client-ip=209.85.167.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so2617655b6e.2 for ; Mon, 22 Jan 2024 16:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705971012; x=1706575812; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gcI3IZKj7A7EP+PZYroCXqSoSDvWd+f5jhzLQV1RU3E=; b=PqnwYr0+OR5sI/TadHmxg50AWg+LUQtxDu5UiI6C7Al9kg7HZg16R7jXjRMF0SxSkc obly3qJjZIm9VGxW/jGpy6OYJ6EMzUu5pvHYq16C049HS1Fbo0WUE+c6yU5SlzJNdleA nqX5U3edXWN4J5LzAyhwxuoIkVGExdB5f7bJA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705971012; x=1706575812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gcI3IZKj7A7EP+PZYroCXqSoSDvWd+f5jhzLQV1RU3E=; b=l1zAW4TYz7qqk+QKQqgvCVynSaPVnVrdG+BKmct29f4w/MbZ1nzTncin2krk+CDiX+ LCMdq5aJLYQHQDhfPlnwuWI03HepFseI8dCnWtWuPMt7wRR6tLCnVKy1kDR4wig/iaNE NOvKMxzzovw3rOOq4Ln0ocDar7subNdDYaTIghCAZvFR/c1Di/PriI31dBvtPaky7rDu F0JcrZRTghqTg0Nau8muOa7kvTldGgfCqGtjWsLTme2rpGkCZ1iFjq1u45qt0T0ERBBQ QDFMbbP75FO2VdFpYkN9mliGULr2RxitOOMxRa+ZI/IC+AL/8z/OfRtrt+cLOqFuO/35 owWw== X-Gm-Message-State: AOJu0YwqjiPy4+pK9anJQ/MLi5cA5RLXITjCeyHMDzrCr9IbIIBq8fkN +OCrOVHAcxS3/td1fG3Zt/Sw8fLB2z5YVhjQyaYtmAY7GF6di0jwSEvBNCqckjmaasoMhZQdocy rph+2 X-Received: by 2002:a05:6808:1a08:b0:3bd:c4ce:a87b with SMTP id bk8-20020a0568081a0800b003bdc4cea87bmr252245oib.43.1705971011765; Mon, 22 Jan 2024 16:50:11 -0800 (PST) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:6e04:285a:ab4d:3428]) by smtp.gmail.com with ESMTPSA id y5-20020aa79e05000000b006d9ef76732esm10190912pfq.213.2024.01.22.16.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:50:10 -0800 (PST) From: Douglas Anderson To: Kees Cook Cc: Arnd Bergmann , Greg Kroah-Hartman , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid tail call optimization Date: Mon, 22 Jan 2024 16:49:35 -0800 Message-ID: <20240122164935.2.I26e8f68c312824fcc80c19d4e91de2d2bef958f0@changeid> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240122164935.1.I345e485f36babad76370c59659a706723750d950@changeid> References: <20240122164935.1.I345e485f36babad76370c59659a706723750d950@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788844116254745391 X-GMAIL-MSGID: 1788844116254745391 When testing with lkdtm_HUNG_TASK() and looking at the output, I expected to see lkdtm_HUNG_TASK() in the stack crawl but it wasn't there. Instead, the top function on at least some devices was schedule() due to tail call optimization. Let's do two things to help here: 1. We'll mark this as "__noreturn". On GCC at least this is documented to prevent tail call optimization. The docs [1] say "In order to preserve backtraces, GCC will never turn calls to noreturn functions into tail calls." 2. We'll add a BUG_ON(1) at the end which means that schedule() is no longer a tail call. Note that this is potentially important because if we _did_ end up returning from schedule() due to some weird issue then we'd potentially be violating the "noreturn" that we told the compiler about. BUG is the right thing to do here. [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html Signed-off-by: Douglas Anderson --- drivers/misc/lkdtm/bugs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index b080eb2335eb..d1222d3eda2f 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -294,10 +294,11 @@ static void lkdtm_SPINLOCKUP(void) __release(&lock_me_up); } -static void lkdtm_HUNG_TASK(void) +static void __noreturn lkdtm_HUNG_TASK(void) { set_current_state(TASK_UNINTERRUPTIBLE); schedule(); + BUG_ON(1); } static volatile unsigned int huge = INT_MAX - 2;