From owner-freebsd-hackers@freebsd.org Thu May 2 01:07:57 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AF64A1583624 for ; Thu, 2 May 2019 01:07:57 +0000 (UTC) (envelope-from jim@netgate.com) Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7D7016E885 for ; Thu, 2 May 2019 01:07:56 +0000 (UTC) (envelope-from jim@netgate.com) Received: by mail-oi1-x231.google.com with SMTP id d62so344036oib.13 for ; Wed, 01 May 2019 18:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netgate.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZDkVypo3cdonfU4KlPbidIu3PZT2qvxgUFF79NfhxZo=; b=O0/5Wisss5Je1IMdNFVIf3CD/k/tIpEW/1jQqT6U1J1lNK+lMO/3P675sOepFIcLF4 Umn1qisOC+AUyhfkNscXCcWH56wiC5EfAYX1ajXTAeHVVQO4ERRLioU2RhhRjkGDHpe2 aiikesBAZym45WFmw1Mx1QIyTo73cVm2hOwes= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZDkVypo3cdonfU4KlPbidIu3PZT2qvxgUFF79NfhxZo=; b=erXyFCcgNrv1eop61ljjEQmLu14qG8ESsKsdkyMX5aeCCqWAWwKysmvmJDg1B9Pdfo pww2q12aBhYiBGAKvCeFz4GVGwHzLLQ+K+tLRCeF9W4G9Ofl6L0NlsQvU4KqEuPYx6uo pyl27KwgxO0yiM1p1y7EYhuPReJMo7m0TiT24wvBD77nKR5y2JOglF+VryOu4Ctdd56a t60ufjKNx6PrwW5ZG1ahpDx+x3+KsrtBa99tWCWTVuoyFnKWCYooQilOYs5T2KmO1wtr 9Go7PtfWITjNY8S923cH5YvMiY7iv3PTWql63qMMRFmWzj+VnnK/ySZq1V9GsU4UpW7J zrgA== X-Gm-Message-State: APjAAAX/Q/uD9AZF0YresVUf6CoAaKy7XfdJXr2w3L0LKqMfkHi+w4uD EqfeRUtSslPP2CRmamI65keFczEmx8xrGA== X-Google-Smtp-Source: APXvYqyGlvUCkUyaFlpbgO22L5pC+EjmXMbuen/TVqzBWOJ82SSKuLDKq2k8sPE2SjIUK4tKQZzKKg== X-Received: by 2002:aca:ecc8:: with SMTP id k191mr809347oih.103.1556759275360; Wed, 01 May 2019 18:07:55 -0700 (PDT) Received: from [10.10.10.235] ([66.196.5.190]) by smtp.gmail.com with ESMTPSA id c3sm10962017otr.57.2019.05.01.18.07.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 18:07:54 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: Re: SIGPIPE from ssh-keyscan [patch] From: Jim Thompson In-Reply-To: <047FD22B-04FB-46EB-96D1-BF6E03080F9F@oitsec.umn.edu> Date: Wed, 1 May 2019 20:07:52 -0500 Cc: FreeBSD Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <144583E1-828D-4450-99B0-4FBF7FC35B26@netgate.com> References: <047FD22B-04FB-46EB-96D1-BF6E03080F9F@oitsec.umn.edu> To: Alan Amesbury X-Mailer: Apple Mail (2.3445.104.8) X-Rspamd-Queue-Id: 7D7016E885 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=netgate.com header.s=google header.b=O0/5Wiss; dmarc=pass (policy=none) header.from=netgate.com; spf=pass (mx1.freebsd.org: domain of jim@netgate.com designates 2607:f8b0:4864:20::231 as permitted sender) smtp.mailfrom=jim@netgate.com X-Spamd-Result: default: False [-6.43 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[netgate.com:s=google]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.945,0]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[netgate.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[netgate.com,none]; RCVD_IN_DNSWL_NONE(0.00)[1.3.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; IP_SCORE(-2.98)[ip: (-9.39), ipnet: 2607:f8b0::/32(-3.19), asn: 15169(-2.25), country: US(-0.06)]; MX_GOOD(-0.01)[alt1.aspmx.l.google.com,aspmx.l.google.com,aspmx5.googlemail.com,aspmx4.googlemail.com,aspmx3.googlemail.com,alt2.aspmx.l.google.com,aspmx2.googlemail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 May 2019 01:07:57 -0000 The remote closed the session for some reason before ssh-keyscan wrote = the greening ("SSH-2.0-OpenSSH-keyscan\r\n=E2=80=9D), so you got SIGPIPE = and ERRNO =3D 32 back from the write call. Arguably the right thing occurred here, with the exception that it = killed your ssh-keyscan process. So perhaps instead of ignoring the signal, you should find out why the = remote is exiting before the local can send its greeting. Otherwise, it=E2=80=99s a bit less heavy-handed to=20 Int set =3D 1; setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); Where sd is the descriptor in question (16 in your example below). But other parts of ssh-keyscan seem to want to know that EPIPE has = occurred, so neither is the correction solution here. Jim > On May 1, 2019, at 5:05 PM, Alan Amesbury = wrote: >=20 > The stock ssh-keyscan bundled with 12.0-RELEASE exits with a SIGPIPE = when it receives weird behavior from hosts it's attempting to = communicate with. Symptoms look like: >=20 >=20 > % ssh-keyscan -f /tmp/randtargetlist > /dev/null > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > Broken pipe > %=20 >=20 >=20 > Output from truss confirms it's SIGPIPE: >=20 > . > . > . > 99597: write(7,"\0\0\^Dd\a\^T\M-Y\M-Jw(E\M-ty"...,1128) =3D 1128 = (0x468) > 99597: select(8,{ 7 },0x0,0x0,{ 5.000000 }) =3D 1 (0x1) > 99597: read(7,"\0\0\^D\M-|\n\^T\M^X\M-N]\M-O\^C"...,8192) =3D 1280 = (0x500) > 99597: write(7,"\0\0\0,\^F\^^\0\0\0 0\M^S\M^J#"...,48) =3D 48 (0x30) > 99597: select(8,{ 7 },0x0,0x0,{ 5.000000 }) =3D 1 (0x1) > 99597: read(7,"\0\0\0\M-<\b\^_\0\0\0003\0\0\0\v"...,8192) =3D 208 = (0xd0) > 99597: write(1,"[REDACTED] ssh-ed255"...,104) =3D 104 (0x68) > 99597: close(7) =3D 0 (0x0) > 99597: write(16,"SSH-2.0-OpenSSH-keyscan\r\n",25) ERR#32 'Broken pipe' > 99597: process killed, signal =3D 13 >=20 >=20 >=20 > The behavior exists in openssh-portable ("$FreeBSD: = head/security/openssh-portable/Makefile 484842 2018-11-12 21:55:35Z = bdrewery $") as well. >=20 > The arguably naive patch I came up with is: >=20 >=20 > --- /tmp/ssh-keyscan.c 2019-05-01 16:09:11.761587000 -0500 > +++ ssh-keyscan.c 2019-05-01 16:08:50.425879000 -0500 > @@ -644,6 +644,8 @@ > int > main(int argc, char **argv) > { > + // ignore SIGPIPE > + signal(SIGPIPE, SIG_IGN); > int debug_flag =3D 0, log_level =3D SYSLOG_LEVEL_INFO; > int opt, fopt_count =3D 0, j; > char *tname, *cp, *line =3D NULL; >=20 >=20 >=20 >=20 > Straightforward and brutish: it ignores SIGPIPE within the main = function in ssh-keyscan.c. This appears to work as expected, e.g.: >=20 >=20 > % ./ssh-keyscan_PATCHED -f /tmp/randtargetlist -T 15 > /dev/null > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > # [REDACTED]:22 SSH-2.0-OpenSSH_7.4 > write ([REDACTED]): Broken pipe > write ([REDACTED]): Broken pipe > write ([REDACTED]): Broken pipe > # [REDACTED]:22 SSH-2.0-babeld-81e0741 > . > . > . >=20 >=20 >=20 > Is this something that's best done by adding it upstream, in the = FreeBSD source (and ports), or ??? Also, is this sane? I don't see it = as a huge deal because it's not a modification to the actual server or = client code, just to the part that grabs host keys, but I freely admit = that I'm outta my depth here. >=20 >=20 > --=20 > Alan >=20 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to = "freebsd-hackers-unsubscribe@freebsd.org"