From nobody Fri Aug 19 19:15:53 2022 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 4M8WgZ1smpz4YvWy; Fri, 19 Aug 2022 19:15:54 +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 4M8WgZ1LXZz3XRh; Fri, 19 Aug 2022 19:15:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660936554; 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=st8aJMg+6MaKFyDUY4qgge4A8rghvyQMtnAElP0xk94=; b=T357OAH+qGqr4akAbr0F28dehx1xWdgqyBiMsMBlZbJIgsYBWDF3QVf2sr2jYh4r8JxkYc fdoPp+ROoF2Ug9bcvDeiJB/sgMWFKynxHkhHt7XW3EkAYDQVsSgHtFVh3GFEN6+5AknU+8 XcrjclgydclHer8TWdpswupZKDS+apz7GU2RH3rbZulCm7tRUzvd3Qd9IMs7iuTWYj3/B+ 8K3qYqvKGsUtbX+gpZSs8UAuRZkYIYDUaUHfHmRLwquTZEXuyoYHo9WAzuo26H9fwv3y8C q+JipUcuuMeMe1l290trazwze+9OWgPXIcddo1Itm/t/6n7BikWp2zbCvhkliA== 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 4M8WgZ0JK3z141B; Fri, 19 Aug 2022 19:15:54 +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 27JJFrIP000989; Fri, 19 Aug 2022 19:15:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27JJFrKA000988; Fri, 19 Aug 2022 19:15:53 GMT (envelope-from git) Date: Fri, 19 Aug 2022 19:15:53 GMT Message-Id: <202208191915.27JJFrKA000988@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: 820bafd0bc14 - main - unix/dgram: don't panic if socket buffer has negative space 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 820bafd0bc14a1448d7e5314e6c9f026518a66de Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660936554; 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=st8aJMg+6MaKFyDUY4qgge4A8rghvyQMtnAElP0xk94=; b=ACeb1aiineRbt6f9dQOEolBThrQBiEs3Gn+lNCe3vHyJBlFAsTxSlE+9gl8vX5o8Z52GeB wgiPo5xcxjjskqd391qy5Ra51r1ryqYLJZmt2oA8v1+Tm6a6Q1ZsnNum+sIY5kAvT7IFUT 4ODeW9t89GtTxxKKhSosDWcwFeS6zW3xqUMkESpwlZkTh/FL8RNAdm10ijYr20MukqfDRt uI8sbNPfAXh/mb+bd2bLvbZeYX5jZb/4ZK8cRbC4ChAcpt5Gu8xOx6tXpGLcgeyeseAmDu hUEt9KL2jw+UrrHpFWW+5CeInHEpTFdAlRkJdnamqhNMwJjIbvPTnlo9MdHgtQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660936554; a=rsa-sha256; cv=none; b=ryu6kPGeP5Z3ZvozzJYM3QLHPDrSm7DtDxcDnCwor23SQK+pM+238VCBWzMp12XsbeS/08 qW+xx45gtefSImaAWd7aJwfXjUP//1o36m0PtU3Nlr6GYjB9rmQ1lHslAWvpcczK9yWqWu M5Z3pZqSGY/h2C2WPPmUqWN+1WotmUA1FK1GyAw3i6yauv2tIi3KTdTjRxYXijkGYGZbwl 21XTWmIdb2sEY0BlyB6A2Zk/PwVREcX4ddhFKJSSDId0DmcMcY/Tp7ouoPA/alnc6mNnij /pmONvis6oFGFMvGzMzo4Flpvi3Z1YeKR4U7LuLrn7Fzy1c70pgjkZ9TK40Gyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=820bafd0bc14a1448d7e5314e6c9f026518a66de commit 820bafd0bc14a1448d7e5314e6c9f026518a66de Author: Gleb Smirnoff AuthorDate: 2022-08-19 19:13:34 +0000 Commit: Gleb Smirnoff CommitDate: 2022-08-19 19:15:38 +0000 unix/dgram: don't panic if socket buffer has negative space That's a legitimate scenario, although unlikely. Reported by: https://syzkaller.appspot.com/bug?extid=6e8be1ec8d77578a3df4 --- sys/kern/uipc_usrreq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 1f2d8a6647b9..2b78c3e51907 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1096,8 +1096,13 @@ uipc_dgram_sbspace(struct sockbuf *sb, u_int cc, u_int mbcnt) { u_int bleft, mleft; - MPASS(sb->sb_hiwat >= sb->uxdg_cc); - MPASS(sb->sb_mbmax >= sb->uxdg_mbcnt); + /* + * Negative space may happen if send(2) is followed by + * setsockopt(SO_SNDBUF/SO_RCVBUF) that shrinks maximum. + */ + if (__predict_false(sb->sb_hiwat < sb->uxdg_cc || + sb->sb_mbmax < sb->uxdg_mbcnt)) + return (false); if (__predict_false(sb->sb_state & SBS_CANTRCVMORE)) return (false);