From nobody Sat Sep 11 14:28:11 2021 X-Original-To: net@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 44AEF17A4E7A; Sat, 11 Sep 2021 14:28:13 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H6FTT1Kqmz3Ltj; Sat, 11 Sep 2021 14:28:13 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from [192.168.0.88] (unknown [195.64.148.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: avg/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 91010E717; Sat, 11 Sep 2021 14:28:12 +0000 (UTC) (envelope-from avg@FreeBSD.org) From: Andriy Gapon To: Mark Johnston Cc: "net@FreeBSD.org" , hackers@freebsd.org References: <500a2272-c1b3-3f97-0096-9fe8117c4b95@FreeBSD.org> <6f455869-cbdd-ee20-f2f8-f633e22071e9@FreeBSD.org> <4a2165c5-b97b-8fb7-9ada-0acae3197824@FreeBSD.org> Subject: Re: recvmsg() "short receive" after FIONREAD Message-ID: <4499e2b0-d1e7-5bee-519c-783fb930fc06@FreeBSD.org> Date: Sat, 11 Sep 2021 17:28:11 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-ThisMailContainsUnwantedMimeParts: N On 11/09/2021 17:16, Andriy Gapon wrote: > On 11/09/2021 17:13, Mark Johnston wrote: >> I think the semantic change is ok.  Did you change FIONREAD to lock the >> sockbuf?  I think it would be necessary to avoid races with pulseaudio: >> sb_acc is modified before sb_ctl, so there could be windows where >> sbavail(sb) - sb->sb_ctl gives a larger. >> >> And, it is not really safe to lock the sockbuf itself, since it may be >> overwritten by a listen(2) call.  SOCK_RECVBUF_LOCK(so) should be used >> instead. > > I didn't think about the locking, so I didn't add it. > My current patch is trivial: > @@ -210,7 +210,7 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct > ucred *active_cred, >                 if (SOLISTENING(so)) { >                         error = EINVAL; >                 } else { > -                       *(int *)data = sbavail(&so->so_rcv); > +                       *(int *)data = sbavail(&so->so_rcv) - so->so_rcv.sb_ctl; >                 } >                 break; > > Let me try adding the lock. By the way, soo_stat() seems to be another good example to follow. -- Andriy Gapon