From nobody Mon Jul 10 14:14:12 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 4R05bT0mG1z4dSQn; Mon, 10 Jul 2023 14:14:13 +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 4R05bT0J4xz4LCR; Mon, 10 Jul 2023 14:14:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688998453; 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=jaKPCgbuK7CCJmN1KY+P3X0orBpHIzjmmbbfofWo43E=; b=nzlvHIG4M2AbuizMuvHLr6FoXwhdhucDODKeBevGkO//5g9Nj1z3FkxmIHL3YtImN1icCq rvCVjAJMR+I4Fp8Ek/9NGfF1dJI5R2Hf4r7+FalwnWO2QEhcc9giBz9PrF2IpAHXgRhq0m 0MZMIU3dGnyPBeNOSZDyacnmYItOieOCgYUk3eVmriXxK+w/8uux3aoe/1xQvMP45w0jET ghrj2TPfaRAhhQAOo8/swgEGmrJQog9E6GPLJnyRxASh2T9Ur3xyRPqNJaxR/wEZcGz0fj qnfO8zQzndSBUkeoRUCelkcdpszeGzEFuMSbGfAer229rJGGRiCyzvRGldeKUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688998453; 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=jaKPCgbuK7CCJmN1KY+P3X0orBpHIzjmmbbfofWo43E=; b=A8crSZwZAFfnkWXCk1/ZN4wMXFMIq2aFHjDau9x9VlLiZtO+MB3riiD8E6ZfyBUjGDqakS addsHR4yBcdH26rZhJv1cZ8csfofwLwwP3asc2o5L0VYIQkmdnbCS11IY+vbyWX5CAzR81 RfrsOfvp9pj4qOoWkQr6+Zg6S8Vt2KTq0hTwdvjz5GMB1UpjVMQ5f/EV3kv9w137mJW3OQ yoqSfkQGWxYD+NabM4t4XelUQo4z0o543HvmJiBNcxhFMB19x+fTZ4shqK54kviKJeUOVK 2L9orZb/TATVU+VMbI+TW5py6nKx7+wKnDWGDN5osYnMLBSjOX4dk/nR36q5RA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688998453; a=rsa-sha256; cv=none; b=W56UmXL/VC3FReLx3AqKxEszV3KzUYo2/JKBXrXUZtmpcfBPaARIjC6xvwEjBUBlDR0QLr z0BdwZSkjFgDJuwk7Mqcr82SQ/V3udOiyPvhAP1xD+61dcioJbS3397OogbQ2DEnP/VoDj s9yqmX3P1bitoKJ1uY6M6v+0sRYulIGFDQj+yTbfDXLkZeARXxKNIG2wptj4xxI6TpbfFB WM+eayKuQJpfkZ/kiOX9yVuxANTtInnVSMOoTsiiQQBpJVgas/yXAFxBPV2mVmEP4DYG/P kEL5O//nrzHHKTXncez0vxONSBM+oSA+aMh/vOp+a+oYrpGMkfRFOlemvoUHuA== 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 4R05bS6TJ9znrv; Mon, 10 Jul 2023 14:14:12 +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 36AEECUh038955; Mon, 10 Jul 2023 14:14:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36AEECfx038954; Mon, 10 Jul 2023 14:14:12 GMT (envelope-from git) Date: Mon, 10 Jul 2023 14:14:12 GMT Message-Id: <202307101414.36AEECfx038954@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 6c049996ec29 - main - During F_SETFL, don't change file flags on error 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: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6c049996ec29bad4a913b019a28f211ab84b0d3d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=6c049996ec29bad4a913b019a28f211ab84b0d3d commit 6c049996ec29bad4a913b019a28f211ab84b0d3d Author: Alan Somers AuthorDate: 2023-07-09 20:48:10 +0000 Commit: Alan Somers CommitDate: 2023-07-10 14:13:58 +0000 During F_SETFL, don't change file flags on error Previously, even if the FIONBIO or FIOASYNC ioctl failed, the file's f_flags variable would still be changed. Now, kern_fcntl will restore the original flags if the ioctl fails. PR: 265736 Reported by: Yuval Pavel Zholkover MFC after: 2 weeks Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40955 --- sys/kern/kern_descrip.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 908c3352514b..ad1b86a0c76c 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -495,7 +495,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) struct vnode *vp; struct mount *mp; struct kinfo_file *kif; - int error, flg, kif_sz, seals, tmp; + int error, flg, kif_sz, seals, tmp, got_set, got_cleared; uint64_t bsize; off_t foffset; @@ -573,12 +573,12 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) tmp &= ~FCNTLFLAGS; tmp |= FFLAGS(arg & ~O_ACCMODE) & FCNTLFLAGS; } while (atomic_cmpset_int(&fp->f_flag, flg, tmp) == 0); + got_set = tmp & ~flg; + got_cleared = flg & ~tmp; tmp = fp->f_flag & FNONBLOCK; error = fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); - if (error != 0) { - fdrop(fp, td); - break; - } + if (error != 0) + goto revert_f_setfl; tmp = fp->f_flag & FASYNC; error = fo_ioctl(fp, FIOASYNC, &tmp, td->td_ucred, td); if (error == 0) { @@ -588,6 +588,13 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) atomic_clear_int(&fp->f_flag, FNONBLOCK); tmp = 0; (void)fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); +revert_f_setfl: + do { + tmp = flg = fp->f_flag; + tmp &= ~FCNTLFLAGS; + tmp |= got_cleared; + tmp &= ~got_set; + } while (atomic_cmpset_int(&fp->f_flag, flg, tmp) == 0); fdrop(fp, td); break;