Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1692594lqm; Fri, 3 May 2024 03:50:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXj9WBvLxcbM6r12ZDTFnv9gq7GKHH9TP5Ezk4dWA+K0y4C8vImdJjVntHbzwfKC/rfyY7Lh7apL5nY29KSBNPw5wF6DdoNp1e8OUgM1w== X-Google-Smtp-Source: AGHT+IEOjBKSAIlN2gBDO4Z6VYX31cEZ+0ltY1nYKuwWccpWd8KlNgUWm4qrjbw0L7l74C31P5rD X-Received: by 2002:a05:622a:190c:b0:43a:b9c9:a25a with SMTP id w12-20020a05622a190c00b0043ab9c9a25amr2366860qtc.56.1714733444436; Fri, 03 May 2024 03:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714733444; cv=none; d=google.com; s=arc-20160816; b=PiOR8wHY5gg2fAdZdMWYss0VGEMLQ2HVntQB07AdK9IuNwaUI9wECASfrGUZLqze7n CgOk6kgJhgr98zdUiF4Uxd6kDP3FVG+zs36swqMJvuhEcceXvoS23Uc/2RLo9tNu2fHf /MSZIguBwlWQTfy7aJqTzFxgSK9N+uaI7fmwjMww8tX9gR3uatPOVfXSb5EAuyEqge9L GPE1hhHDuFuJyBhNMZbLIKPnm1Ht8+8dzE6p501+smnifAeqZHx/wcMIBUHqkKCOXYfU vKVQkUk+AWtLArvDc8ACL4lBS4Ttsjwtx1PZ6lf0mubyyaX7yWLaWlvO082KiAN/YIHk eyaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:blahblahblah:openpgp:user-agent:mail-followup-to:references :in-reply-to:message-id:cc:to:from:author:date:dkim-signature :dkim-signature:delivered-to:delivered-to:reply-to:list-id :list-subscribe:list-unsubscribe:list-help:list-post:precedence :mailing-list; bh=26VqTBFXo5b9t6vC5Ir1/RqgnzkPDF0CwmJHuySAYiU=; fh=0vp24Lj378x/X362xiVl8Vj+OxVAgFKic8fOjnKNvjo=; b=y0P+9+zfpdXn16t5TcrA4Ya0LyETvUPIO3gkukWR/WBy02J2Syll6ibKQGpdLwxiR/ OZSw/IfDqCdlU0/zhvGRLzyH/e34Bz1TygLY7OKuc1mF4dqthOz/QaFf1QxvK/k5Wrkw HD/ZhrDjYHSmnA31Cu5TLWctGE0orlFQPaLBvrJk/wKbaNWwJ/44bAkVML8y6vta5cLa xEatK5YKCBZ4afXzvlqVkFPWuWYSqT+z9IhmFlKl1oLG0vUPMHAXzBLyBLCuMWSUq22O QTydWo+WfJGfiznEDFuXSe9cKy37U968J4fMj3gk1zC5qEnLJcW14RgWXzObZLA23MA5 cyeA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sdaoden.eu header.s=citron header.b=jxtc9BP5; dkim=neutral (no key) header.i=@sdaoden.eu header.s=orange; spf=pass (google.com: domain of oss-security-return-30116-linux.lists.archive=gmail.com@lists.openwall.com designates 193.110.157.125 as permitted sender) smtp.mailfrom="oss-security-return-30116-linux.lists.archive=gmail.com@lists.openwall.com" Return-Path: Received: from second.openwall.net (second.openwall.net. [193.110.157.125]) by mx.google.com with SMTP id o9-20020a05622a008900b004398463202esi3126198qtw.19.2024.05.03.03.50.43 for ; Fri, 03 May 2024 03:50:44 -0700 (PDT) Received-SPF: pass (google.com: domain of oss-security-return-30116-linux.lists.archive=gmail.com@lists.openwall.com designates 193.110.157.125 as permitted sender) client-ip=193.110.157.125; Authentication-Results: mx.google.com; dkim=pass header.i=@sdaoden.eu header.s=citron header.b=jxtc9BP5; dkim=neutral (no key) header.i=@sdaoden.eu header.s=orange; spf=pass (google.com: domain of oss-security-return-30116-linux.lists.archive=gmail.com@lists.openwall.com designates 193.110.157.125 as permitted sender) smtp.mailfrom="oss-security-return-30116-linux.lists.archive=gmail.com@lists.openwall.com" Received: (qmail 26619 invoked by uid 550); 3 May 2024 10:47:53 -0000 Mailing-List: contact oss-security-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: oss-security@lists.openwall.com Delivered-To: mailing list oss-security@lists.openwall.com Delivered-To: moderator for oss-security@lists.openwall.com Received: (qmail 11684 invoked from network); 2 May 2024 23:04:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sdaoden.eu; s=citron; t=1714691038; x=1715357704; h=date:author:from:to:cc:subject: message-id:in-reply-to:references:mail-followup-to:openpgp:blahblahblah: author:from:subject:date:to:cc:resent-date:resent-from:resent-to: resent-cc:in-reply-to:references:mime-version:content-type: content-transfer-encoding:message-id:mail-followup-to:openpgp: blahblahblah; bh=26VqTBFXo5b9t6vC5Ir1/RqgnzkPDF0CwmJHuySAYiU=; b=jxtc9BP5k1OEM0RP4QMs0Yu+USSFz3qqOOgTaVoVLa9IRXsKuI+Wv1CQw+fosh+tlEUMbRfK NeQgxjd3C5R7M3kNOUzrdrSpfBSxmhI+BRkmcWH20C/JphHWIRHRLlyjviYqsSd0PNSMbCWaIl tk5igCemaQHVLfIWQjemMThFWiUzyPLGbxU1yh6YkRImFBnGSK/uJNFRa6u4ArlsL8B8DJX7tk twW14Mp+GmMDSnEjE4oXinHZ2Yyn9q/UgfZvQiYFPmwgqbmXfqwcYSVTtyVB129+DP68XrT5fj G32kR3O3TUWKnnaOkgqQ8tLDioT9uEfq9f4r0Kyn63RXn2sQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=sdaoden.eu; s=orange; t=1714691038; x=1715357704; h=date:author:from:to:cc:subject: message-id:in-reply-to:references:mail-followup-to:openpgp:blahblahblah: author:from:subject:date:to:cc:resent-date:resent-from:resent-to: resent-cc:in-reply-to:references:mime-version:content-type: content-transfer-encoding:message-id:mail-followup-to:openpgp: blahblahblah; bh=26VqTBFXo5b9t6vC5Ir1/RqgnzkPDF0CwmJHuySAYiU=; b=Awr+kJkOSU8P7nsmm1ezeDCbIjmnSHhzlCH5jnuvSSsBZ2HQATlYU0URg6bW8Rz5QVX3qs8/ lNPLx7nhFPJPBQ== Date: Fri, 03 May 2024 01:03:58 +0200 Author: Steffen Nurpmeso From: Steffen Nurpmeso To: Sam James Cc: Solar Designer , oss-security@lists.openwall.com Message-ID: <20240502230358.F7YB0d6D@steffen%sdaoden.eu> In-Reply-To: <20240502223912.08A3RYp4@steffen%sdaoden.eu> References: <20240329155126.kjjfduxw2yrlxgzm@awork3.anarazel.de> <20240331213023.GA22787@openwall.com> <20240403205835.GA12974@openwall.com> <87o79nlwxl.fsf@gentoo.org> <20240502223912.08A3RYp4@steffen%sdaoden.eu> Mail-Followup-To: Sam James , Solar Designer , oss-security@lists.openwall.com User-Agent: s-nail v14.9.24-621-g0d1e55f367 OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD; url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. Subject: Re: [oss-security] escaping terminal control characters (was Re: backdoor in upstream xz/liblzma leading to ssh server compromise) Steffen Nurpmeso wrote in <20240502223912.08A3RYp4@steffen%sdaoden.eu>: |Sam James wrote in | <87o79nlwxl.fsf@gentoo.org>: ||Solar Designer writes: ||> On Wed, Apr 03, 2024 at 11:03:17AM +1100, Matthew Fernandez wrote: ||>> On 4/1/24 08:30, Solar Designer wrote: ||>>>On Sat, Mar 30, 2024 at 04:37:48PM -0000, Tavis Ormandy wrote: ... ||>> Is the currently accepted wisdom that any application printing to ||>> stdout/stderr should take steps to avoid control characters in the ||>> output? ||> ||> First, let's limit this to cases where the control characters come from ||> potentially untrusted input to the program. Obviously, many programs ||> generate terminal escapes on their own (usually via a library), for ||> their intended functionality (colorized listings, TUIs, etc.) Some ||> programs pass potential control characters from their trusted input. ||> ||> Second, I think no, there isn't currently an established opinion on ||> whether programs should perform such filtering of untrusted input. || ||Lasse has put up an initial implementation for xz: ||https://github.com/tukaani-project/xz/pull/118. || ||Comments are welcome. It was a TODO from a long time ago ;) || ||We're not sure how much is overkill (or underkill) for this, especially ||given it gets harder when Unicode is involved. || ||> [...] | |For this purpose there exists the (very very expensive) | | https://man.netbsd.org/vis.3 | |series of functions. Or you do something like this, where "isuni" |gives you "this is a UTF-8 nl_langinfo(CODESET)". ... | if((wc & ~S(wchar_t,037)) == 0) | wc = isuni ? 0x2400 | wc : '?'; | else if(wc == 0177) | wc = isuni ? 0x2421 : '?'; | else | wc = isuni ? 0x2426 : '?'; ... |This can be made better (for example the above requires "wc" to be |an actual ISO 10646 codepoint, which ISO C etc), but the key point |is that the Unicode standard gives you everything needed to |properly mask these sequences, from its very beginning in 1993: | | 2400..2424 ; 1.1 # [37] SYMBOL FOR NULL..SYMBOL FOR NEWLINE | |and i have yet to see a font which does not support those. |(Whether and how users can make sense of them totally aside.) |Of course you loose the copy&paste capability. While here please let me back the not yet gracefully supported shell escape mechanism $''. The current approach seems to be to be as atomic as possible: # touch $(printf 'a\rb\tc\a') # ll -> -rw-r----- 1 steffen steffen 0 May 3 00:46 'c'$'\a' -rw-r----- 1 steffen steffen 0 May 3 00:46 'a'$'\r''b' (GNU coreutils). Isn't that just terrible? In (the development version of) my mailer tab-completion leads to #..mbox? /tmp/ $'a\rb' $'c\a' which i find at least a little bit better. (Do not even think about looking in its implementation though, look ICU or what.) And even though currently unsupported, it should be said that with "grapheme clusters" and in general things like ligatures and other such language-specific constructs which need to look at surroundings -- in general interfaces like towupper() etc are not useful in global context, entire sentences have to be looked at as a whole due to this! --, shell quotes should be extended to the largest possible range possible. Ie, all the iconv(3)s that are currently used because of a lack of other interfaces should be enabled to see the longest possible (sub)string, not the most atomar, as seen above. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)