From nobody Thu Sep 05 00:40:42 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 4WzgWb1WNBz5W7yC; Thu, 05 Sep 2024 00:40:43 +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 4WzgWb10PCz4Mcs; Thu, 5 Sep 2024 00:40:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725496843; 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=jVTKeMHujsrXi5xauHjhiCQNq+LCXRcjs+9qryJ0yqs=; b=RifMRM5Iwhr+Kffo4SQmJEpaYQaMxc2HKy2gwFhfMqf4exo+NXJaF4WCnq6wsKdzEHiLtV kbX3pO0lzoINCmTYn4UI300cIio2gS/WqimlRQR64jORFWFIYP0Q+T7kWcSfcqLZCUPOFi Xasc/ac2F9SM8LX1R4dqTByvf6SKMuTeaGouPhYR/HnHW9vm1mrI3mP+BMhcoAZYIKOe5n H+3UCdpkRV0QijMj1wFdQRb/rFSIdwSO3yv9rFxO+ijkpISKzJaXxJQNeJ6CT0IBwpjaez 8ZiYym72SweePVk4WCc3+EBXT3SM7rjiSglh4Fbr1J3mUtojklHk9wVdXG2OGw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725496843; a=rsa-sha256; cv=none; b=eD2ik1QQJk+ZbWBpROTmV8EF8+GE9iMYW95oQCEGkK5m5l1KXAyjGTHoW7nH4WKdyiuP2x TkEiAwL9+iZPz0kk3VaFgEB+UxJjW5cWN5GEslLfGj2bcXRTlwzokS24ByTfmLNOmSrAyK fOtOeOKW1bP9q7uPRvsL4kzVbHegJvEF3e8hC+uYm/K1i30hXD/WS0pLTPQP7HFVURTcSM lj0PaGjSxoOm+l7sPGyPmGxQQvyQVE44fYh+X+iviBjFzIq2SJyxeOs+ld4wTZrCugYThr fmshcjMvB4F0z3sZwU01sIf7DadwnevttOaFF6Y+PG8KMgeLS8T/nnxY7T/mFg== 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=1725496843; 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=jVTKeMHujsrXi5xauHjhiCQNq+LCXRcjs+9qryJ0yqs=; b=WmBfpUWYChi6hzxfph2X9pY3cVR89ZOw4e/0ZjY8lhrs1NX29M6N4+vINh6Sd40agXXbqR w0BszPN+VflhloT++e0SzeqBR2JOCzJoRSDwnWmvKFVUCdOF5auPCWYEJeSi/w0coAg6Yy mUeBjDdTO+uipKfawmUv4M1M260/dKpGi+qBUOenyfnib12jUlYeVKYZONZTPPqbmMk8uW cSYSS+dmMv0BH3WZp0zdXyh3HqAMJ/9JV5R4APOG/iQQG5lh8Ec9vdaDBHCtS60bmVWi0H 3mEMdUWwk+1i6XgOt647yTA/JfaUuReM8ZQnuPhlhk/Yh1IQOsjyjBOt9upBHg== 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 4WzgWb0V1nzmbj; Thu, 5 Sep 2024 00:40:43 +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 4850egZa019402; Thu, 5 Sep 2024 00:40:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4850egxl019399; Thu, 5 Sep 2024 00:40:42 GMT (envelope-from git) Date: Thu, 5 Sep 2024 00:40:42 GMT Message-Id: <202409050040.4850egxl019399@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 79eba754bec3 - main - vop_stdadvise(): restore correct handling of length == 0 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 79eba754bec39d88a6494318a2176d19743cf993 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=79eba754bec39d88a6494318a2176d19743cf993 commit 79eba754bec39d88a6494318a2176d19743cf993 Author: Konstantin Belousov AuthorDate: 2024-09-03 04:20:40 +0000 Commit: Konstantin Belousov CommitDate: 2024-09-05 00:40:14 +0000 vop_stdadvise(): restore correct handling of length == 0 Switch to unsigned arithmetic to handle overflow not relying on -fwrap, and specially treat the case of length == 0 from posix_fadvise() which passes OFF_MAX as the end to VOP. There, roundup() overflows and -fwrap causes bend and endn become negative. Using uintmax_t gives the place for roundup() to not wrap. Also remove locals with single use, and move calculations out from under bo lock. Reported by: tmunro Reviewed by: markj, tmunro Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46518 --- sys/kern/vfs_default.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index d612642a6bc9..f5722851d729 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -1063,8 +1063,8 @@ vop_stdadvise(struct vop_advise_args *ap) { struct vnode *vp; struct bufobj *bo; + uintmax_t bstart, bend; daddr_t startn, endn; - off_t bstart, bend, start, end; int bsize, error; vp = ap->a_vp; @@ -1096,7 +1096,8 @@ vop_stdadvise(struct vop_advise_args *ap) */ bsize = vp->v_bufobj.bo_bsize; bstart = rounddown(ap->a_start, bsize); - bend = roundup(ap->a_end, bsize); + bend = ap->a_end; + bend = roundup(bend, bsize); /* * Deactivate pages in the specified range from the backing VM @@ -1105,18 +1106,17 @@ vop_stdadvise(struct vop_advise_args *ap) * below. */ if (vp->v_object != NULL) { - start = trunc_page(bstart); - end = round_page(bend); VM_OBJECT_RLOCK(vp->v_object); - vm_object_page_noreuse(vp->v_object, OFF_TO_IDX(start), - OFF_TO_IDX(end)); + vm_object_page_noreuse(vp->v_object, + OFF_TO_IDX(trunc_page(bstart)), + OFF_TO_IDX(round_page(bend))); VM_OBJECT_RUNLOCK(vp->v_object); } bo = &vp->v_bufobj; - BO_RLOCK(bo); startn = bstart / bsize; endn = bend / bsize; + BO_RLOCK(bo); error = bnoreuselist(&bo->bo_clean, bo, startn, endn); if (error == 0) error = bnoreuselist(&bo->bo_dirty, bo, startn, endn);