From nobody Wed Apr 17 14:43:06 2024 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 4VKNtf5Zczz5H2Ws; Wed, 17 Apr 2024 14:43:06 +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 4VKNtf3n0xz50bJ; Wed, 17 Apr 2024 14:43:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713364986; 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=Km9WLeobKpRLOhy+0otnvxpue0EXxM8RJChfWT9EWQs=; b=uXM4tn7jzLRYVLEM6v4l9hmo0qLmkYHq+Ap8+UWM7upzCDaLUxaIJibIgCNAH9yPvT/msl mmBAuWnXEYbN/sCJPuBS7nqgJBhwiTws5aC+FA0o74chAjX12xN57GhtENHdi/GtCAR8ng SgU7JpXlfrJFZUr/P3EvcLg2tAHc0Q+W+pmiduonNrDY5RoYNAwGkPnX/dWVQief+6hju1 PMWU7s/jx4xuV9gdyjj8+AlFMnpxRPvgKos0vBH/gG2cwQ9DrrLRIPeLq5I7hDoDRWMwOv on2JGh4OBGfe8tz21zQT7C0KmnRaZJuYRFLI9c+smNNZJjIdlRg++jKYMDXynQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713364986; a=rsa-sha256; cv=none; b=tDMNlyf46LWD5MZZPMxJFZo+a1q/iSNSlwjlXnQN4+4LjKp5OzvbF9JxbpljLk50q10IrH 36XUSjLWT4Fwop44RiJYeLagaKiKx7VAizmhDwj1Yypy2iksLw7ZDUPKI4lmMvsLe8Zd1W Wj8iiOXtgJiJyyVOMzqvC3yPjFin28hVudypFW8c7tj6hX2j1qdGPs82PFFNm48B9b8sSm 2u36xRjtH1Mih3amZ0qoW4yyL6g7ceRFempQtZQ13fjU5BqBBUfBSAVcgt2cQMjQJoHY/b lRmsKqd3wVO3sGCCcqMVrqEeYfpOWkBlS9bCG5ti4vwJ3XrZkwMYoi1M+Edi5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713364986; 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=Km9WLeobKpRLOhy+0otnvxpue0EXxM8RJChfWT9EWQs=; b=s2gNNuXM9jiaBVpSx6Rh6t51LBsK0/I4sIdQa8ueB0a2WP3mY8a6uCZbie10ZHxplx3oPR HqyH+A7Lu33gfW3yfi6mRRPVdely+FhdBIY+LhoNFlsZGDcC8aKVqXw06tmnDCYQKYjsL2 EqpWokgyAAr007h5QYfii7Cmx+2fyTA/v4PP+Ke9yj87j+WP3lhiAbu1O56dNKHDAHBgrL p+2cv/6J3DT/432C02aH2kX/wm9jTwX56ofomljAfK3C1ea5NgECWp9gfltITuwg+3gdJD U0XZRnKk9+4UImt0zdhWzZBf7W9x/bz3zxhh21fdrwKKz4rjGwUPM69Wm/yYYw== 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 4VKNtf39qWzWv3; Wed, 17 Apr 2024 14:43:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43HEh6wJ022705; Wed, 17 Apr 2024 14:43:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43HEh6pZ022701; Wed, 17 Apr 2024 14:43:06 GMT (envelope-from git) Date: Wed, 17 Apr 2024 14:43:06 GMT Message-Id: <202404171443.43HEh6pZ022701@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b7e4666d7b69 - main - nfsserver: Rate-limit messages about requests from unprivileged ports 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b7e4666d7b69c22699a9299687018a892a5dad5b Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b7e4666d7b69c22699a9299687018a892a5dad5b commit b7e4666d7b69c22699a9299687018a892a5dad5b Author: Mark Johnston AuthorDate: 2024-04-17 14:36:58 +0000 Commit: Mark Johnston CommitDate: 2024-04-17 14:36:58 +0000 nfsserver: Rate-limit messages about requests from unprivileged ports If access from unreserved ports is disabled, then a remote host can cause an NFS server to log a message by sending a packet. This is useful for diagnosing problems but bad for resiliency in the case where the server is being spammed with a large number of rejected requests. Limit prints to once per second (racily). Reviewed by: rmacklem, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44819 --- sys/fs/nfsserver/nfs_nfsdkrpc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdkrpc.c b/sys/fs/nfsserver/nfs_nfsdkrpc.c index 25f9c05d6f0b..022f7403d28b 100644 --- a/sys/fs/nfsserver/nfs_nfsdkrpc.c +++ b/sys/fs/nfsserver/nfs_nfsdkrpc.c @@ -191,6 +191,12 @@ nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt) port = ntohs(sin->sin_port); if (port >= IPPORT_RESERVED && nd.nd_procnum != NFSPROC_NULL) { + static struct timeval privport_ratecheck = { + .tv_sec = 0, .tv_usec = 0 + }; + static const struct timeval privport_ratecheck_int = { + .tv_sec = 1, .tv_usec = 0 + }; #ifdef INET6 char buf[INET6_ADDRSTRLEN]; #else @@ -208,15 +214,19 @@ nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt) (buf)) #endif #endif - printf("NFS request from unprivileged port (%s:%d)\n", + if (ratecheck(&privport_ratecheck, + &privport_ratecheck_int)) { + printf( + "NFS request from unprivileged port (%s:%d)\n", #ifdef INET6 - sin->sin_family == AF_INET6 ? - ip6_sprintf(buf, &satosin6(sin)->sin6_addr) : + sin->sin_family == AF_INET6 ? + ip6_sprintf(buf, &satosin6(sin)->sin6_addr) : #if defined(KLD_MODULE) #undef ip6_sprintf #endif #endif - inet_ntoa_r(sin->sin_addr, buf), port); + inet_ntoa_r(sin->sin_addr, buf), port); + } svcerr_weakauth(rqst); svc_freereq(rqst); m_freem(nd.nd_mrep);