From nobody Fri Jun 24 16:10:42 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 38DC886643C; Fri, 24 Jun 2022 16:10:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LV2Ck476Nz3JRZ; Fri, 24 Jun 2022 16:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oB8c9R/pIy6pbUa1Q9xPJGz9rEmZZrYngOlPhz7P+GU=; b=cbVZ+RMh+gLWdxGTCV5oNJsaUDreR/THDjO3Mu74rokk2TGFzHRFoBC7tEm3usZe+fOIID yUZI/C12QDpzWJT0SB6Y/jhQ7RyyK+eOzHUhRI0Vrjgl6MDIGGzC/j4sXU9P0JBtAfxRqV ohy2v91iojQHvzn0YvJ/Y8dm1zCpUsspv8+/nHwYwlRjxtinsqFbruZrq1m5SwoMcsjKDa RypssiJqAnQUjmdNr0OkX0bYR+SJpVN4D2WM/ZwzAkUsJuqXpR+SRfQttUSP2qZ8GUESJ2 B88rl/xTqWDyA3X6wgltuOlWtrwdyiiXDLv51eIEHNOrs2GKPNKgKTcSiop2bA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5012913224; Fri, 24 Jun 2022 16:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25OGAgj8006370; Fri, 24 Jun 2022 16:10:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25OGAgxA006369; Fri, 24 Jun 2022 16:10:42 GMT (envelope-from git) Date: Fri, 24 Jun 2022 16:10:42 GMT Message-Id: <202206241610.25OGAgxA006369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: ddc689051917 - main - libc/syslog: deprecate use of "/var/run/logpriv" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ddc689051917e739a90d1335ff40591c7601397c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oB8c9R/pIy6pbUa1Q9xPJGz9rEmZZrYngOlPhz7P+GU=; b=Aj29kG1m84lGCu/M/yhQMh4m1yzUhzw0YvBNBhBF6mP4oV1a94VnshLGBpquqSwAO5fHJL jdZxb9tqHgKlaKKg+hW6mte2YaQtEO7eos6H2vBJF2SIInPVMJSr/5GKCGBP52Krt4Q08Y 3eFRCGKysFxqiAD9cgsGMvwwjF74p2cCDsMxUCGYAOL2bl0d2Ye4tGukbo8iytsyWfg7wT DsZIt9rH8iPNE40w0LCQl1toaQTxGhM6l/VJ+B6HL6KPIjvUszKgEdB4hx8tQFWQCnogZp rTqLC/IEeMWsdHuZw/PElwFwMmnwvh2/vWl+Ys8Ss3mrPbc8ob5JJ/mSN/7F3A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656087043; a=rsa-sha256; cv=none; b=TtEZ+lt9wxh2Um/MB7UTWcNRgJ2HELtFYLuBoVoTGQp7PEWnfAqF8oN/CT/KUy6qzwkq7t mbO3nezzjJw+b2Abc9yG/7Tjnn+puoUa1bTwZcPwv+7qWSqdOFCoHSc60Nv7zc4RyBmOGL IMzGPVTaFXKUhqWPpiHTXpwnfkAlTHY5oqBYvpvBG5ubruDCeeohMvXH3BY6oMMs0/Qt6R 7UpInCgODxFNSbvav6EolXkI2IIYfzth3ewPPUjiPYZlRNB1hIhWQyMNwY/Ngl/aDIescS fujAp/yOfVtPUL9u8ODwecm7RjE1AcVW0MOiC78n6LBDq85eoBchKnhj/avDfw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=ddc689051917e739a90d1335ff40591c7601397c commit ddc689051917e739a90d1335ff40591c7601397c Author: Gleb Smirnoff AuthorDate: 2022-06-24 16:09:11 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-24 16:09:11 +0000 libc/syslog: deprecate use of "/var/run/logpriv" This additional socket was created in 2e89951b6f20 and 240d5a9b1ce76 to try workaround problems with classic PF_UNIX/SOCK_DGRAM sockets. With recent changes in kernel this trick is no longer needed, so the trick can be reverted. In syslogd(8) we would still create the socket for the next several major releases for compatibility. Differential revision: https://reviews.freebsd.org/D35305 --- lib/libc/gen/syslog.c | 75 ++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 61 deletions(-) diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 50a77f651980..a466b4cbc49e 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -61,7 +62,7 @@ __FBSDID("$FreeBSD$"); #define MAXLINE 8192 static int LogFile = -1; /* fd for log */ -static int status; /* connection status */ +static bool connected; /* have done connect */ static int opened; /* have done openlog() */ static int LogStat = 0; /* status bits, set by openlog() */ static const char *LogTag = NULL; /* string to tag the entry with */ @@ -85,12 +86,6 @@ static void disconnectlog(void); /* disconnect from syslogd */ static void connectlog(void); /* (re)connect to syslogd */ static void openlog_unlocked(const char *, int, int); -enum { - NOCONN = 0, - CONNDEF, - CONNPRIV, -}; - /* * Format of the magic cookie passed through the stdio hook */ @@ -291,48 +286,19 @@ vsyslog1(int pri, const char *fmt, va_list ap) connectlog(); /* - * If the send() fails, there are two likely scenarios: - * 1) syslogd was restarted - * 2) /var/run/log is out of socket buffer space, which - * in most cases means local DoS. - * If the error does not indicate a full buffer, we address - * case #1 by attempting to reconnect to /var/run/log[priv] - * and resending the message once. - * - * If we are working with a privileged socket, the retry - * attempts end there, because we don't want to freeze a - * critical application like su(1) or sshd(8). - * - * Otherwise, we address case #2 by repeatedly retrying the - * send() to give syslogd a chance to empty its socket buffer. + * If the send() failed, there are two likely scenarios: + * 1) syslogd was restarted. In this case make one (only) attempt + * to reconnect. + * 2) We filled our buffer due to syslogd not being able to read + * as fast as we write. In this case prefer to lose the current + * message rather than whole buffer of previously logged data. */ - if (send(LogFile, tbuf, cnt, 0) < 0) { if (errno != ENOBUFS) { - /* - * Scenario 1: syslogd was restarted - * reconnect and resend once - */ disconnectlog(); connectlog(); if (send(LogFile, tbuf, cnt, 0) >= 0) return; - /* - * if the resend failed, fall through to - * possible scenario 2 - */ - } - while (errno == ENOBUFS) { - /* - * Scenario 2: out of socket buffer space - * possible DoS, fail fast on a privileged - * socket - */ - if (status == CONNPRIV) - break; - _usleep(1); - if (send(LogFile, tbuf, cnt, 0) >= 0) - return; } } else return; @@ -389,7 +355,7 @@ disconnectlog(void) _close(LogFile); LogFile = -1; } - status = NOCONN; /* retry connect */ + connected = false; /* retry connect */ } /* Should be called with mutex acquired */ @@ -413,29 +379,16 @@ connectlog(void) } } } - if (LogFile != -1 && status == NOCONN) { + if (!connected) { SyslogAddr.sun_len = sizeof(SyslogAddr); SyslogAddr.sun_family = AF_UNIX; - /* - * First try privileged socket. If no success, - * then try default socket. - */ - (void)strncpy(SyslogAddr.sun_path, _PATH_LOG_PRIV, + (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, sizeof SyslogAddr.sun_path); if (_connect(LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) != -1) - status = CONNPRIV; - - if (status == NOCONN) { - (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, - sizeof SyslogAddr.sun_path); - if (_connect(LogFile, (struct sockaddr *)&SyslogAddr, - sizeof(SyslogAddr)) != -1) - status = CONNDEF; - } - - if (status == NOCONN) { + connected = true; + else { (void)_close(LogFile); LogFile = -1; } @@ -477,7 +430,7 @@ closelog(void) LogFile = -1; } LogTag = NULL; - status = NOCONN; + connected = false; THREAD_UNLOCK(); }