Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2500963rdb; Wed, 15 Nov 2023 02:34:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJfamgyrAYrkrm7tipNQo/sOY5rAHOp1if5VQjOIWJ9kKMwK6lkloRX57B1/tm2XFl9Fhu X-Received: by 2002:a05:6870:fe96:b0:1ea:647f:a9b6 with SMTP id qm22-20020a056870fe9600b001ea647fa9b6mr14247087oab.44.1700044475639; Wed, 15 Nov 2023 02:34:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700044475; cv=none; d=google.com; s=arc-20160816; b=yMeTfsbVC67y5HCwGx7D3DABLMzEQeCZBzOiqDy2aFiasrnfC0Iga3EbgY1bqYBZxy UsoTcZqKdPZij7TTVrys1w4Vo5yp0tskSxYWo1NiTeHctrZQF2TzuCWwtmaiv7ebBus1 ukRbANFbROis5ysalhJcsc4jexbQb1apzZ2KiI/eMERW5nk72xm6gJOip6XmWNzUmheK GyZjUz0np7llxPGeJuf6FizKH3qRUkP/WWD4ZL5IMsSi8KU9E6a2wRqykJ0zmD3NLqF8 xu9jjmfM3+hveHwSmkORzlJ4ge11eT2arw6XZzRAtahgMPl5uTErR4T2xdD+d7ve1wTT E6Sw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=E8FSWsbMO8tcuITVdz2DD/j08+FVO7RNb3LNjMBTSA4=; fh=6j36m1jHKU7KTFZCDlX/JQDgr7Jf8Wr470TB4VSI5uk=; b=tdnX9G8p9K/nmQbsKvmhIqhyeEC/4fyAT13l7nTCjJFpJSQ0tmlREjHpQLr+b6m6ll 2xD+eR22/Q2HLyCao4m3e8LeE6SAh7Im2eKEOTmpvqkottT5d7B6OjXQrjxGQ2DUoKiL QsKWlkJeOIOnbtxtP4ZAEMen427/Ne5hW1hL3Xc6ByLjekD/387sZ3ktOfTX7+3oRdiH 4EInRv+YFiW2RJiI4n0nAX/gWrZEfnbzjqHryNFFKH3VVar3FeIrsvmmO0lr2nyrIRz2 tVpiEDf55cQP3VX8HZc2Nr7DcPMRhIyVm6S3PB9eVpkXQgu209KEYJo+a/N5J9mql3Fr wtVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id fb21-20020a056a002d9500b0069335e0c824si10402001pfb.204.2023.11.15.02.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 02:34:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 93E9F8020718; Wed, 15 Nov 2023 02:34:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbjKOKeS (ORCPT + 99 others); Wed, 15 Nov 2023 05:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234098AbjKOKeS (ORCPT ); Wed, 15 Nov 2023 05:34:18 -0500 Received: from harvie.cz (harvie.cz [77.87.242.242]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 833F310F; Wed, 15 Nov 2023 02:34:14 -0800 (PST) Received: from anemophobia.amit.cz (unknown [31.30.84.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by harvie.cz (Postfix) with ESMTPSA id 901211801BF; Wed, 15 Nov 2023 11:34:13 +0100 (CET) From: Tomas Mudrunka To: jirislaby@kernel.org Cc: corbet@lwn.net, gregkh@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, rdunlap@infradead.org, tomas.mudrunka@gmail.com Subject: [PATCH v9] /proc/sysrq-trigger: accept multiple keys at once Date: Wed, 15 Nov 2023 11:34:08 +0100 Message-ID: <20231115103408.193561-1-tomas.mudrunka@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <670993bf-a8ef-4561-8213-6a37d0598d83@kernel.org> References: <670993bf-a8ef-4561-8213-6a37d0598d83@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 02:34:32 -0800 (PST) Just for convenience. This way we can do: `echo _reisub > /proc/sysrq-trigger` Instead of: `for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;` This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach. Signed-off-by: Tomas Mudrunka --- V8 -> V9: Fixed english bit more V7 -> V8: Added this list of changes V6 -> V7: Fixed english in documentation V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo) V1 -> V2: Bulk mode only activated by underscore now, added docs Documentation/admin-guide/sysrq.rst | 11 ++++++++++- drivers/tty/sysrq.c | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guide/sysrq.rst index 51906e473..0042fa26b 100644 --- a/Documentation/admin-guide/sysrq.rst +++ b/Documentation/admin-guide/sysrq.rst @@ -75,10 +75,19 @@ On other submit a patch to be included in this section. On all - Write a character to /proc/sysrq-trigger. e.g.:: + Write a single character to /proc/sysrq-trigger. + Only the first character is processed, the rest of string is ignored. + However, it is not recommended to write any extra characters + as the behavior is undefined and might change in the future versions. + E.g.:: echo t > /proc/sysrq-trigger + Alternatively, write multiple characters prepended by underscore. + This way, all characters will be processed. E.g.:: + + echo _reisub > /proc/sysrq-trigger + The :kbd:`` is case sensitive. What are the 'command' keys? diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 6b4a28bcf..5411351e4 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -1150,16 +1150,28 @@ EXPORT_SYMBOL(unregister_sysrq_key); #ifdef CONFIG_PROC_FS /* * writing 'C' to /proc/sysrq-trigger is like sysrq-C + * Normally only the first character written is processed. + * If first character is underscore, all characters are processed. */ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - if (count) { + bool bulk = false; + size_t i; + + for (i = 0; i < count; i++) { char c; - if (get_user(c, buf)) + if (get_user(c, buf + i)) return -EFAULT; - __handle_sysrq(c, false); + + if (c == '_') + bulk = true; + else + __handle_sysrq(c, false); + + if (!bulk) + break; } return count; -- 2.42.1