From nobody Fri Mar 10 13:29:21 2023 X-Original-To: dev-commits-src-main@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 4PY6N220djz3xX6X; Fri, 10 Mar 2023 13:29:22 +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 4PY6N21XQxz3RJW; Fri, 10 Mar 2023 13:29:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454962; 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=uMHVVVPyuFwixkHvMnK2Lwh4+MAcbcxI2XCZF64N+Jg=; b=tuB67LEa9py39il5/kW0mXt8h/+iAmAeqgMt4XFxnhxHl/zb8Ss2S7N4nFF7Lvv7JPHsbe yBAWnNwWhKBpmdiYvFORbOZsW+c2oKIHEJZpVLWeXsraY2LHf5osYoiwjYLyx7zPozxaXW PkAXQ6won5oxestKuPhzIovjtmoNUjRRs4oLR7V1FZcfdwY29hBvFWcbdYs8F3jgcgJmlc q5IEWcC8/tA1w1bRpyBElQYG+pQWmpQbVX72ue28tbeT1goM61p9UvkpzeWQ6Lf6NOOhy9 goRfY+wEY5HTiW/igZiXnLD0jpJXrcXZlg2XahFZgn9tfbgEFyPRCZwS4RqoBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454962; 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=uMHVVVPyuFwixkHvMnK2Lwh4+MAcbcxI2XCZF64N+Jg=; b=DZzCgrRCoC351sfvPhjHDHH7NvwS/tVrglOysw3BKVY1WGOwNMF2sgBVziD3NvQ3vIglBh NnyXd+vTuFNOzgl4ADKvaMZL24YDNq+fcKLX6DOTYs5alyDWpYT4lxA5cAeWhFbrXfIZFo Tifi3p4LlxxqwMl4W5g+RHs4Yn6yHANvtjXVP8YOw/zsYtNAu9u3x7gTfqs1LJleoZKrCD S4ySxz6OFmQ8ssKeO4aVgfRrcHtNvTYCbnzJaVnLn+s3QHUrrNZ9W/xhQ+oR0wOLNruMDt Hi/yFOAZdlL0QvUGNvBm8nBBhQsHDQMxIJA/rNmo5IwMUnoC74I4885GwpJbQA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678454962; a=rsa-sha256; cv=none; b=GsHfU/DBlrzmr2z0/Kx8oXlaxRHdu8NnCj8SBrF3PnRjxjAQOr+k+CJ2172wiTzY9Hmxen 0sXgKV7mRT264AQGvT7CNEBJG6QgcVTzbxdO6sCb5wA0PoNTP4rckacmWljoFK22FCaBva ZfK3J1h3yRhMGM/4y+KVDeXAG7nz4dy0NT29oDApMy81vf85RPn26lbh+8ZTuSktM48uN9 4sc7rex/yF9LPGTaKLTLYjE0GmXL3uaq1f1DaNykaKR9I5ji0Zw/nox8Q2ZEHlleyhrheh nEKJ6zrhaoo1mB/mGy/LP0jhZ+p8chuMjXZREXTBc8NuRBEpI9uMQ0auTTXd/g== 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 4PY6N20cHWzqSW; Fri, 10 Mar 2023 13:29:22 +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 32ADTLK4090153; Fri, 10 Mar 2023 13:29:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32ADTLbA090152; Fri, 10 Mar 2023 13:29:21 GMT (envelope-from git) Date: Fri, 10 Mar 2023 13:29:21 GMT Message-Id: <202303101329.32ADTLbA090152@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: b4736c90adb8 - main - tftpd: Don't consume arbitrary requests when failing to fork. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b4736c90adb84032aaf1e3bcb8988916a82ed5de Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b4736c90adb84032aaf1e3bcb8988916a82ed5de commit b4736c90adb84032aaf1e3bcb8988916a82ed5de Author: Dag-Erling Smørgrav AuthorDate: 2023-03-10 13:24:44 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-03-10 13:25:16 +0000 tftpd: Don't consume arbitrary requests when failing to fork. We've already consumed one request, which is sufficient to prevent inetd from endlessly restarting us in this particular and extremely unlikely case. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38967 --- libexec/tftpd/tftpd.c | 52 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 4b8a3024fe5a..8e3d2e13f320 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -134,7 +134,8 @@ main(int argc, char *argv[]) struct passwd *nobody; const char *chuser = "nobody"; char recvbuffer[MAXPKTSIZE]; - int allow_ro = 1, allow_wo = 1; + int allow_ro = 1, allow_wo = 1, on = 1; + pid_t pid; tzset(); /* syslog in localtime */ acting_as_client = 0; @@ -222,12 +223,9 @@ main(int argc, char *argv[]) umask(mask); - { - int on = 1; - if (ioctl(0, FIONBIO, &on) < 0) { - tftp_log(LOG_ERR, "ioctl(FIONBIO): %s", strerror(errno)); - exit(1); - } + if (ioctl(0, FIONBIO, &on) < 0) { + tftp_log(LOG_ERR, "ioctl(FIONBIO): %s", strerror(errno)); + exit(1); } /* Find out who we are talking to and what we are going to do */ @@ -255,40 +253,14 @@ main(int argc, char *argv[]) * break before doing the above "recvfrom", inetd would * spawn endless instances, clogging the system. */ - { - int i, pid; - - for (i = 1; i < 20; i++) { - pid = fork(); - if (pid < 0) { - sleep(i); - /* - * flush out to most recently sent request. - * - * This may drop some request, but those - * will be resent by the clients when - * they timeout. The positive effect of - * this flush is to (try to) prevent more - * than one tftpd being started up to service - * a single request from a single client. - */ - peerlen = sizeof peer_sock; - i = recvfrom(0, recvbuffer, MAXPKTSIZE, 0, - (struct sockaddr *)&peer_sock, &peerlen); - if (i > 0) { - n = i; - } - } else { - break; - } - } - if (pid < 0) { - tftp_log(LOG_ERR, "fork: %s", strerror(errno)); - exit(1); - } else if (pid != 0) { - exit(0); - } + pid = fork(); + if (pid < 0) { + tftp_log(LOG_ERR, "fork: %s", strerror(errno)); + exit(1); + } else if (pid != 0) { + exit(0); } + /* child */ #ifdef LIBWRAP /*