]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
sshd: update the libwrap patch to drop connections early
authorGleb Smirnoff <glebius@FreeBSD.org>
Mon, 3 Jan 2022 02:32:30 +0000 (18:32 -0800)
committerEd Maste <emaste@FreeBSD.org>
Fri, 7 Oct 2022 01:39:00 +0000 (21:39 -0400)
commit46aaea6c19ef1f377936eede16b4bdb626421dd6
treea83ecae88c818b8404061d41e46ed7769342a7b9
parent6dca51b9f32dd3f6a0dd58a0f1525db3d27f485d
sshd: update the libwrap patch to drop connections early

OpenSSH has dropped libwrap support in OpenSSH 6.7p in 2014
(f2719b7c in github.com/openssh/openssh-portable) and we
maintain the patch ourselves since 2016 (a0ee8cc636cd).

Over the years, the libwrap support has deteriotated and probably
that was reason for removal upstream.  Original idea of libwrap was
to drop illegitimate connection as soon as possible, but over the
years the code was pushed further down and down and ended in the
forked client connection handler.

The negative effects of late dropping is increasing attack surface
for hosts that are to be dropped anyway.  Apart from hypothetical
future vulnerabilities in connection handling, today a malicious
host listed in /etc/hosts.allow still can trigger sshd to enter
connection throttling mode, which is enabled by default (see
MaxStartups in sshd_config(5)), effectively casting DoS attack.
Note that on OpenBSD this attack isn't possible, since they enable
MaxStartups together with UseBlacklist.

A only negative effect from early drop, that I can imagine, is that
now main listener parses file in /etc, and if our root filesystems
goes bad, it would get stuck.  But unlikely you'd be able to login
in that case anyway.

Implementation details:

- For brevity we reuse the same struct request_info.  This isn't
  a documented feature of libwrap, but code review, viewing data
  in a debugger and real life testing shows that if we clear
  RQ_CLIENT_NAME and RQ_CLIENT_ADDR every time, it works as intended.
- We set SO_LINGER on the socket to force immediate connection reset.
- We log message exactly as libwrap's refuse() would do.

Differential revision: https://reviews.freebsd.org/D33044

(cherry picked from commit ca573c9a1779bdeeea6d0a6e948676555977737e)
crypto/openssh/sshd.c