From nobody Mon Nov 29 22:05:28 2021 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 2955818C7927; Mon, 29 Nov 2021 22:05:30 +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 4J2ztd1SPZz3GNR; Mon, 29 Nov 2021 22:05:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E5B822597; Mon, 29 Nov 2021 22:05:28 +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 1ATM5Sxr075561; Mon, 29 Nov 2021 22:05:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ATM5Sll075560; Mon, 29 Nov 2021 22:05:28 GMT (envelope-from git) Date: Mon, 29 Nov 2021 22:05:28 GMT Message-Id: <202111292205.1ATM5Sll075560@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 28f047188492 - main - uipc: rework recvfrom, getsockname, getpeername 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: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 28f047188492c8f2ddca66f162fd2ac9bdc170a6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638223529; 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=UyVp2pN3Bk3+B5ym+wBaGpUfTN+xEwlnXENyO30JQVo=; b=m44rPwp5n382xM9nRWDp0wpewBtYPivjpmo9uzwy3pUX0iU+CcEAOgI7IO1seoOp0vb9Ml ZtElz/v5SnfIv27z77FEWgZI7lUhdb8K6DuefcVLuEqnJCSMBt0135pOM5E32g8j8QgOjf ndezGy5NGL4ZPFZw4bds7NmqiqrYzv1uDU5+JQRI2nMkJu7wu5qUqqM6mLSNrBt7ns3P15 3PgbdXTYfYRXAUOexQh2oAOBwcibUBZdKwR3965HZaiJnhyjazwcB944aytu2bhijUC+x/ K+SYYDeFXU7DdbKoW8KmGI6caWXnquCk9g9E2fpvqncTFTOo/cGJgxcl1Kj44Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638223529; a=rsa-sha256; cv=none; b=cTL87BmtBSi8ICXs+ARsKboscuBmEXskWT1Ky8qGFr63lIvSRCzUWqlwooyT0R6ilOL/qY PD5F7EWonfftc/d6tOXxh/vd7vyQBPKwQQttg4ZDFip9HGni6EymMw0oRNzGpwV2K9TEtT oUDRE2d+UjlhQgku4tT6i2Xjgm7AdbTD4wtitv249Lm/ZTAYX4jYpvb0mPujqx5fEwoSYG OPcY3/YjiN1tKJPLGG7vs7ZLWORzPsmD604RnwrGCFvmJIF07Zuoj8yI+Kxa/JxOfh4uBO ge4wg3Soe6lQUOKASMqtYJTG2gx57d5ZFJ+75JPsBXF3DsB820wWyqaNEDUq2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=28f047188492c8f2ddca66f162fd2ac9bdc170a6 commit 28f047188492c8f2ddca66f162fd2ac9bdc170a6 Author: Brooks Davis AuthorDate: 2021-11-29 22:02:59 +0000 Commit: Brooks Davis CommitDate: 2021-11-29 22:04:41 +0000 uipc: rework recvfrom, getsockname, getpeername Stop using _args structs as part of internal kernel APIs. Add a kern_recvfrom and adjust getsockname and getpeername's equivalent functions to take individual arguments rather than a uap pointer. Adopt a convention from CheriBSD that a function interacting with userspace pointers and sitting between the sys_ syscall and kern_ implementation is named user_. Reviewed by: kib, imp --- sys/kern/uipc_syscalls.c | 79 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 44079bae1e9b..3111ce7e16e4 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -78,10 +78,6 @@ static int recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp); static int accept1(struct thread *td, int s, struct sockaddr *uname, socklen_t *anamelen, int flags); -static int getsockname1(struct thread *td, struct getsockname_args *uap, - int compat); -static int getpeername1(struct thread *td, struct getpeername_args *uap, - int compat); static int sockargs(struct mbuf **, char *, socklen_t, int); /* @@ -1069,40 +1065,48 @@ recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp) return (error); } -int -sys_recvfrom(struct thread *td, struct recvfrom_args *uap) +static int +kern_recvfrom(struct thread *td, int s, void *buf, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlenaddr) { struct msghdr msg; struct iovec aiov; int error; - if (uap->fromlenaddr) { - error = copyin(uap->fromlenaddr, - &msg.msg_namelen, sizeof (msg.msg_namelen)); + if (fromlenaddr != NULL) { + error = copyin(fromlenaddr, &msg.msg_namelen, + sizeof (msg.msg_namelen)); if (error != 0) goto done2; } else { msg.msg_namelen = 0; } - msg.msg_name = uap->from; + msg.msg_name = from; msg.msg_iov = &aiov; msg.msg_iovlen = 1; - aiov.iov_base = uap->buf; - aiov.iov_len = uap->len; + aiov.iov_base = buf; + aiov.iov_len = len; msg.msg_control = 0; - msg.msg_flags = uap->flags; - error = recvit(td, uap->s, &msg, uap->fromlenaddr); + msg.msg_flags = flags; + error = recvit(td, s, &msg, fromlenaddr); done2: return (error); } +int +sys_recvfrom(struct thread *td, struct recvfrom_args *uap) +{ + return (kern_recvfrom(td, uap->s, uap->buf, uap->len, + uap->flags, uap->from, uap->fromlenaddr)); +} + + #ifdef COMPAT_OLDSOCK int orecvfrom(struct thread *td, struct recvfrom_args *uap) { - - uap->flags |= MSG_COMPAT; - return (sys_recvfrom(td, uap)); + return (kern_recvfrom(td, uap->s, uap->buf, uap->len, + uap->flags | MSG_COMPAT, uap->from, uap->fromlenaddr)); } #endif @@ -1331,21 +1335,19 @@ kern_getsockopt(struct thread *td, int s, int level, int name, void *val, return (error); } -/* - * getsockname1() - Get socket name. - */ static int -getsockname1(struct thread *td, struct getsockname_args *uap, int compat) +user_getsockname(struct thread *td, int fdes, struct sockaddr *asa, + socklen_t *alen, bool compat) { struct sockaddr *sa; socklen_t len; int error; - error = copyin(uap->alen, &len, sizeof(len)); + error = copyin(alen, &len, sizeof(len)); if (error != 0) return (error); - error = kern_getsockname(td, uap->fdes, &sa, &len); + error = kern_getsockname(td, fdes, &sa, &len); if (error != 0) return (error); @@ -1354,11 +1356,11 @@ getsockname1(struct thread *td, struct getsockname_args *uap, int compat) if (compat && SV_PROC_FLAG(td->td_proc, SV_AOUT)) ((struct osockaddr *)sa)->sa_family = sa->sa_family; #endif - error = copyout(sa, uap->asa, (u_int)len); + error = copyout(sa, asa, len); } free(sa, M_SONAME); if (error == 0) - error = copyout(&len, uap->alen, sizeof(len)); + error = copyout(&len, alen, sizeof(len)); return (error); } @@ -1404,34 +1406,30 @@ bad: int sys_getsockname(struct thread *td, struct getsockname_args *uap) { - - return (getsockname1(td, uap, 0)); + return (user_getsockname(td, uap->fdes, uap->asa, uap->alen, false)); } #ifdef COMPAT_OLDSOCK int ogetsockname(struct thread *td, struct getsockname_args *uap) { - - return (getsockname1(td, uap, 1)); + return (user_getsockname(td, uap->fdes, uap->asa, uap->alen, true)); } #endif /* COMPAT_OLDSOCK */ -/* - * getpeername1() - Get name of peer for connected socket. - */ static int -getpeername1(struct thread *td, struct getpeername_args *uap, int compat) +user_getpeername(struct thread *td, int fdes, struct sockaddr *asa, + socklen_t *alen, int compat) { struct sockaddr *sa; socklen_t len; int error; - error = copyin(uap->alen, &len, sizeof (len)); + error = copyin(alen, &len, sizeof (len)); if (error != 0) return (error); - error = kern_getpeername(td, uap->fdes, &sa, &len); + error = kern_getpeername(td, fdes, &sa, &len); if (error != 0) return (error); @@ -1440,11 +1438,11 @@ getpeername1(struct thread *td, struct getpeername_args *uap, int compat) if (compat && SV_PROC_FLAG(td->td_proc, SV_AOUT)) ((struct osockaddr *)sa)->sa_family = sa->sa_family; #endif - error = copyout(sa, uap->asa, (u_int)len); + error = copyout(sa, asa, len); } free(sa, M_SONAME); if (error == 0) - error = copyout(&len, uap->alen, sizeof(len)); + error = copyout(&len, alen, sizeof(len)); return (error); } @@ -1495,17 +1493,14 @@ done: int sys_getpeername(struct thread *td, struct getpeername_args *uap) { - - return (getpeername1(td, uap, 0)); + return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, 0)); } #ifdef COMPAT_OLDSOCK int ogetpeername(struct thread *td, struct ogetpeername_args *uap) { - - /* XXX uap should have type `getpeername_args *' to begin with. */ - return (getpeername1(td, (struct getpeername_args *)uap, 1)); + return (user_getpeername(td, uap->fdes, uap->asa, uap->alen, 1)); } #endif /* COMPAT_OLDSOCK */