From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Max Nikulin Newsgroups: gmane.emacs.bugs Subject: bug#66390: `man' allows to inject arbitrary shell code Date: Sun, 8 Oct 2023 10:37:33 +0700 Message-ID: References: <83wmvyzir2.fsf@gnu.org> <585dcaf0-358e-4a9d-84d1-6fd9c2c8aec5@gmail.com> <83v8bizf9r.fsf@gnu.org> <1865abb8-16cd-4570-9a8a-87cf9430583d@gmail.com> <875y3iigua.fsf@gmx.de> <83o7hazap7.fsf@gnu.org> <87mswugyoq.fsf@gmx.de> <83jzryz6op.fsf@gnu.org> <87a5sugwcx.fsf@gmx.de> <83h6n2z3tr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37288"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 66390@debbugs.gnu.org To: Eli Zaretskii , Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 08 05:39:08 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qpKdH-0009ZY-Lz for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 08 Oct 2023 05:39:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpKcu-0000AE-5g; Sat, 07 Oct 2023 23:38:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qpKcs-00009r-TD for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 23:38:42 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpKcs-0007Mv-LF for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 23:38:42 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qpKdC-000221-1s for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 23:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Max Nikulin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Oct 2023 03:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66390 X-GNU-PR-Package: emacs Original-Received: via spool by 66390-submit@debbugs.gnu.org id=B66390.16967362857737 (code B ref 66390); Sun, 08 Oct 2023 03:39:02 +0000 Original-Received: (at 66390) by debbugs.gnu.org; 8 Oct 2023 03:38:05 +0000 Original-Received: from localhost ([127.0.0.1]:56115 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpKcG-00020i-MH for submit@debbugs.gnu.org; Sat, 07 Oct 2023 23:38:04 -0400 Original-Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]:51409) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpKcE-000209-7z for 66390@debbugs.gnu.org; Sat, 07 Oct 2023 23:38:02 -0400 Original-Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2c038a1e2e6so40096741fa.2 for <66390@debbugs.gnu.org>; Sat, 07 Oct 2023 20:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696736256; x=1697341056; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=FrlOfTzL5iTJK4HK8o0kk50IbNpz3zMXKXM8ceq4es0=; b=b1xy7Er22CY0uyLBJFS75X+qF08DnaV9ICcxkItkfu/tEoCXkDkxl8pBft8WWCWnU4 PJbep9lk0nAwdCXNQlHSbhrkNKP3bR9vxFyGbmaJbKWiPwSmQIvWg2PdtKveeYj+vMD6 CBIWDJapXRgBMDMQdZnGEHPuGzzT5ahN75MpR5izJy/y5TV6kN24s/HZwd5q2VvGrhaT l4pPZJm+oEOk+1PoxhkqplRJ0OsKzX2skrs7E9TZ9+ivzt1l/TDmbGREdCZgVPdKVeCX W1IxeWlVRJovFTx1hbfJwlXKWlWLZ7kI+VRbybCQR7Gqw13w3sq4wQ7KBdTudpbzvK7n u/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696736256; x=1697341056; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FrlOfTzL5iTJK4HK8o0kk50IbNpz3zMXKXM8ceq4es0=; b=Udgm0JWVj4xaHF5is6ZKIhbW5t61GnqoNd13+lA9aNpdKooBvQeVok4n9S9H7ZdMkM rC56SSdatiqzThTy0MBeoAs6W13465S3bX3XvI2rNGb//r9OV8tm8vn8Rns781dJTD0x LAqvKYX2/kx/33JU2gitRXKzQBO1oS/BWHRVP0f/EQqiy70BVTyBjoU9HkLhOCKtTDb5 bq5KBONadRm901TthU0PESFR7VDMPoU0Gn/Issl/UlU+L4T8INSAfZMECd9SDENb7SX+ 03uU+7nhiKbfDKVlmLTyL8kTzx0PBQW/nwBNGjRwXkPto+XnP9AshCLciXQihDOImf/1 Z5Mg== X-Gm-Message-State: AOJu0Yy39tY2wEq5h60wTj8o5fk9PMVd5X+kVH/G8SGobtbIW+z+Pq8l Wi3RGHFlInwPB/QmgDJr8fo= X-Google-Smtp-Source: AGHT+IEWXZEXrjJ+JqYCjlaYogIudKo4xbP1GdS2G1Dnv0F0j+sSHfDb180b67/qnykJzJsmu3Q0ew== X-Received: by 2002:a2e:8310:0:b0:2c0:a99:68e7 with SMTP id a16-20020a2e8310000000b002c00a9968e7mr10782764ljh.19.1696736255661; Sat, 07 Oct 2023 20:37:35 -0700 (PDT) Original-Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.188]) by smtp.googlemail.com with ESMTPSA id o18-20020a2e7312000000b002ba586d27a2sm1421419ljc.26.2023.10.07.20.37.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 20:37:35 -0700 (PDT) Content-Language: en-US, ru-RU In-Reply-To: <83h6n2z3tr.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272055 Archived-At: On 08/10/2023 01:26, Eli Zaretskii wrote: > > So the problem _is_ with the shell? If so, the best way of avoiding > these problems is not invoke 'man' via the shell, but via call-process > and its ilk instead. It will be great if it is possible to avoid shell in the middle. However - man.el uses pipes with sed and awk to post-process output of man executable. - if support of remote man files is considered then it is even more hard to avoid shell. SSH assumes shell commands. I had in mind using at least `shell-quote-argument'. The issues of sanitizing outputs in callers - If there was a safe function in man.el then callers code would be more simple, so it would be less probable to introduce bugs in such code. - behavior of the `man' emacs command is *underspecified*, so it is hard to provide safe argument for it. Some parenthesis are allowed as in "man(1)" others may be interpreted by shell. - `shell-quote-argument' in callers would rely on man.el implementation details at best or may even lead to undefined behavior since I see have no way to bypass some processing of the argument of the `man' emacs command. Execution a part of `man' emacs command argument by shell is a surprise to the user any case. Ideally elisp code should prevent it and man.el should emit an error. Attempts to call of `man' from other packages is an open door for security vulnerabilities. I was really surprised when I noticed that various Linux distributions patched and updated emacs even in stable releases in response to https://security-tracker.debian.org/tracker/CVE-2023-28617 Formally the score of this CVE was high.