From nobody Fri Jan 20 21:56:41 2023 X-Original-To: dev-commits-src-all@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 4NzCy21XRQz316FP; Fri, 20 Jan 2023 21:56:42 +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 4NzCy204nWz3lMd; Fri, 20 Jan 2023 21:56:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674251802; 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=GR0oOb2Fu3clWqrLFfJHP7OC7tC2NZq/D4Brz+lTeLE=; b=IOX7buIFHRP95oHPhaBIPHVX66/L28zvJWoPJ9IV8l1u5TJ4f9I+fkuHr3G9X3mGpG00JH JuIpEcQpAr86Ha0cBk1fQZ/+Ct+HCuSCA2vqQgpjTKLZm0ZxmDR/9FCKBv2L6DyG/PqUsk Fo0SPNB8TUcy6JrcmTrJ72KAL7oYYdtD98AJo4yF9MXF/+GKwlanDrkdpAARzW1aYr5t7V o14dkY51fFelq6npEi8kZSKjk7RivqZg92RPgJIuLjbOJTcfIu0aFriBVlnq6ygIuP7GDB eDSI364bXwW5cFFzK8gZ1YAOhS4X/v0inW7Fii6StDcEU34026k+I+5FW7jguQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674251802; 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=GR0oOb2Fu3clWqrLFfJHP7OC7tC2NZq/D4Brz+lTeLE=; b=EZeJkYeIn+BxodcYReMxH8X3iPsF8z5GaFQ60Jp88Z3IgS2Q/B6qJOYMQc3ByY8E5vEpFo um0KpJUzwNK7G8FyqJObnyHAtJPuRmi8cC/t4W6SK3EUbraPsENxU/02zI1wgSALBuAXtf bLaqozRSLtDsRyG3AC5lTa4mpwB0zJ8x1E1dhL3AiHGJUhzttV2aMGdNJgZScwULBD3+3l bzHb6Wcdo4zKpGOxbGhZHGv80VbMviHR/6mOpuaIuWvy08KYre0I7exwMyxsDZyjnBT5ts zYneqKa6Q3GmkKc/QbG9QwOEBDyK+Ng5D0ApHnLyEouU/OWC2yZZdAMkSkLgiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674251802; a=rsa-sha256; cv=none; b=ZWEI7IG8I3eJEIqbPhHlkxUHX+ZCJR+UqKkMMcprjWw20PLtRhhbJfEj4u1I/nknLNHt4g l0d4g/VC9UNQEkHApVXdoHWm/1LERfqKvyMaTAEhI99DQ2sc7SCDzRMZG031xSCImfOWhw cZd1upUMDYHo/i7AZPzGkpAO0z8hysxU8H6BeeCUETsW12CjtW+FnjC9A3t2I0cYzs65cw 7MQU0RHDqpKVGgdkgBXPYBk4ayC9C6lI5eolON4RaJIwAQ/tV8N4M8cKdVBIIY6OYseFkv 37126lHuf+cU2Suk5lPM9/LZ8rIJuB3xb9Y5U4+lvZZfEixaXLMVKmDWVuRV7g== 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 4NzCy16Dm6zlyD; Fri, 20 Jan 2023 21:56:41 +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 30KLufhW030559; Fri, 20 Jan 2023 21:56:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30KLufOn030558; Fri, 20 Jan 2023 21:56:41 GMT (envelope-from git) Date: Fri, 20 Jan 2023 21:56:41 GMT Message-Id: <202301202156.30KLufOn030558@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: 456f05756bbd - main - Handle int rank issues in in vn_getsize_locked() and vn_seek() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 456f05756bbdd818f7b2474faeef0d4d7baecd69 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=456f05756bbdd818f7b2474faeef0d4d7baecd69 commit 456f05756bbdd818f7b2474faeef0d4d7baecd69 Author: Konstantin Belousov AuthorDate: 2023-01-20 06:45:35 +0000 Commit: Konstantin Belousov CommitDate: 2023-01-20 21:56:29 +0000 Handle int rank issues in in vn_getsize_locked() and vn_seek() In vn_getsize_locked(), when storing vattr.va_size of type u_quad_t into off_t size, we must avoid overflow. Then, the check for fsize < 0, introduced in the commit f45feecfb27ca51067d6789eaa43547cadc4990b 'vfs: add vn_getsize', is nop [1]. Reported and reviewed by: jhb Coverity CID: 1502346 Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38133 --- sys/kern/vfs_subr.c | 9 +++++++-- sys/kern/vfs_vnops.c | 4 +--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index a1a73f2ddf38..008e646f2b7f 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -7128,8 +7129,12 @@ vn_getsize_locked(struct vnode *vp, off_t *size, struct ucred *cred) ASSERT_VOP_LOCKED(vp, __func__); error = VOP_GETATTR(vp, &vattr, cred); - if (__predict_true(error == 0)) - *size = vattr.va_size; + if (__predict_true(error == 0)) { + if (vattr.va_size <= OFF_MAX) + *size = vattr.va_size; + else + error = EFBIG; + } return (error); } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index f3a6360eb250..48d15ce6ab25 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -2656,9 +2656,7 @@ vn_seek(struct file *fp, off_t offset, int whence, struct thread *td) if (fsize == 0 && vp->v_type == VCHR && fo_ioctl(fp, DIOCGMEDIASIZE, &size, cred, td) == 0) fsize = size; - if (noneg && - (fsize > OFF_MAX || - (offset > 0 && fsize > OFF_MAX - offset))) { + if (noneg && offset > 0 && fsize > OFF_MAX - offset) { error = EOVERFLOW; break; }