From nobody Tue May 6 19:34:40 2025 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 4ZsT9r6pkBz5vJyW; Tue, 06 May 2025 19:34:40 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZsT9r5WQgz3rK1; Tue, 06 May 2025 19:34:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746560080; 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=NaH9Fhqrld0ILeYSlu4FR3qRIc81g+7J1D+OQYpMHr4=; b=tqzFo/1A90nLpRmxDHdsR/GjuaaDCdOdqWNmznuEMI/6AzeVuTk9gg1cXor6MCeoGEXY19 ltTy4TLmCVlsa6amKfOs9ULVpoGgvdTXfcF24hAYak8gdc3IELyMvFdzdThaqL+E1NU/HK Mf+dhSCobbkPuHqmPG7nX/WjXxKL8Osr5ikry8WP9yXn4aLM+2N3h9+fJPihHo2TJm3n2s NMpu/g6uPpBZitXHdZRaHPEhe59mjcf87o3tjT5QdNztAs5B2m6tby/X23ue7AR0PKJcn2 V30bcs8Yth6mCS2rSNZOanIhzU2zXZiAoofgxKt1JwkM9hIGE+WsBy/tk1QHWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746560080; 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=NaH9Fhqrld0ILeYSlu4FR3qRIc81g+7J1D+OQYpMHr4=; b=PPwU85sy+VWJr3QecZV5+il24Ablk5y5LcLqBhjP/CRuzqQ0J4H5aedhUWGPoG+J7cFTRW Va7TZlCfwuiZI0EgbNyOGO4khTnkNCMcIEXrCXDFVod+wChrEOCOHq+5c8DtVcYTGqD9A2 AZzhW95R731ALaGCVqLK2BP7n1wi6Lwf3yqjaIFmO90omc7Te8g6cEdc4fp843dGFbrozb t4S67zw8/kOdO1k6j06Veq7uaTdnMsekN8m64Ch/I0g7Reja8HfXf4Jjc6AYC1W0qeab5F alEySA0Ad+8Dom27T2GVlEoC4ZONewW8Fuw+oN5CnZOaOi/zfdGoa0rVFcaEtA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746560080; a=rsa-sha256; cv=none; b=BZhhSj3TmUoUqv383oICGrsIhnLznOcXDTfPYSlYijRhY/Y5jGkLSDAVdxBCjjpOikJd0t OSxYLDF1rkd7xVo+rhe0LwnIEadzYEcYeUME206Sh7DJBEbihmq8/nIFCcML66r/xZ29oX vAPLkmV3eEWHmbPXnkJVq3shYJQltuy35m+IjhQ/ugJNa6e03cvSWs1FgRm2WF54RQvw+1 SvyQ1wL8x8Ujq0RZbeWoR4MdlE+4PrFgIuTBzmBo6dn7EkHdwp4F15dKu1M2CJS7E+j0AU nWVwLBFxOsBB0/lR96jfBYMsDw2XnH3KTBplVPCrKDwxyjQTAR7SiTdoKm/O/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4ZsT9r47ppz1CV6; Tue, 06 May 2025 19:34:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 546JYeL8056491; Tue, 6 May 2025 19:34:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 546JYexL056488; Tue, 6 May 2025 19:34:40 GMT (envelope-from git) Date: Tue, 6 May 2025 19:34:40 GMT Message-Id: <202505061934.546JYexL056488@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: 9a7d03c7df35 - main - sendfile: cover the entire sendfile operation under CURVNET_SET() 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9a7d03c7df3536cdb5faf0848c6dab4a5d7bcef8 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9a7d03c7df3536cdb5faf0848c6dab4a5d7bcef8 commit 9a7d03c7df3536cdb5faf0848c6dab4a5d7bcef8 Author: Gleb Smirnoff AuthorDate: 2025-05-06 18:15:15 +0000 Commit: Gleb Smirnoff CommitDate: 2025-05-06 19:34:26 +0000 sendfile: cover the entire sendfile operation under CURVNET_SET() There is no reason to set/restore for every single pr_send(), as it never changes. Also, cover call into pr_sendfile_wait with CURVNET_SET() fixing recent regression in unix(4). Now we would enter sendfile_iodone() with curvnet set, when called synchronously. Although, it is easy to tell a syncronous call from I/O completion, unfortunately the vnet(9) macros do not support conditional invocation, so just change CURVNET_SET() to CURVNET_SET_QUIET() and add a comment that we are aware of the recursion. Reported-by: syzbot+7b0b20cf2c672c181d98@syzkaller.appspotmail.com --- sys/kern/kern_sendfile.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_sendfile.c b/sys/kern/kern_sendfile.c index 1fd1828c37c7..c428d80e0e1a 100644 --- a/sys/kern/kern_sendfile.c +++ b/sys/kern/kern_sendfile.c @@ -285,6 +285,11 @@ sendfile_iowait(struct sf_io *sfio, const char *wmesg) /* * I/O completion callback. + * + * When called via I/O path, the curvnet is not set and should be obtained + * from the socket. When called synchronously from vn_sendfile(), usually + * to report error or just release the reference (all pages are valid), then + * curvnet shall be already set. */ static void sendfile_iodone(void *arg, vm_page_t *pa, int count, int error) @@ -365,7 +370,7 @@ sendfile_iodone(void *arg, vm_page_t *pa, int count, int error) ("non-ext_pgs mbuf with TLS session")); #endif so = sfio->so; - CURVNET_SET(so->so_vnet); + CURVNET_SET_QUIET(so->so_vnet); if (__predict_false(sfio->error)) { /* * I/O operation failed. The state of data in the socket @@ -782,6 +787,7 @@ vn_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, error = sendfile_getsock(td, sockfd, &sock_fp, &so); if (error != 0) goto out; + CURVNET_SET(so->so_vnet); pr = so->so_proto; #ifdef MAC @@ -1161,7 +1167,6 @@ prepend_header: ("%s: mlen %u space %d hdrlen %d", __func__, m_length(m, NULL), space, hdrlen)); - CURVNET_SET(so->so_vnet); #ifdef KERN_TLS if (tls != NULL) ktls_frame(m, tls, &tls_enq_cnt, TLS_RLTYPE_APP); @@ -1203,8 +1208,6 @@ prepend_header: tcp_log_sendfile(so, offset, nbytes, flags); } #endif - CURVNET_RESTORE(); - m = NULL; if (error) goto done; @@ -1265,9 +1268,9 @@ out: if (tls != NULL) ktls_free(tls); #endif - if (error == ERESTART) error = EINTR; + CURVNET_RESTORE(); return (error); }