From nobody Fri Jun 17 19:41:07 2022 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 E924885D6F5; Fri, 17 Jun 2022 19:41:09 +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 4LPqCm1HjPz3j1P; Fri, 17 Jun 2022 19:41:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494868; 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=BRvEH6/S3Q6tnaFj0IaC/OrOvkI501OnySRVd37KRnQ=; b=ZDe84m5raOokI2LksffYjL7reiXpLhFbXR2tPg0rxZKp7sy5em8uAVchXFF750VSZS+kc0 9Gv5W81IvSFQfgNncPMoaL7Txr/uL+6pGC0aieF20ywppyxRBuAHjTuMWFUvbBc/2qfMdk 9NuNDfchZaKeFTdPfSomgzzcvdupvFJGZ/os99otnb7zriVpPeVghljJeOlnVmtSroAyE1 C0HKctZ/dBsQOvUzKSzGzXRGLAUYNGgrpjAcL9U0bR+4riHKOkZKcToW2H1nH5rGFsPvON hXxTjr7IygD8o97AcG7jGYRyP27xhU4rcjQim9YvZixjySAvuddC11PEYBNQ9Q== 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 A85AA25DA8; Fri, 17 Jun 2022 19:41:07 +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 25HJf7US030059; Fri, 17 Jun 2022 19:41:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJf7Wx030058; Fri, 17 Jun 2022 19:41:07 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:41:07 GMT Message-Id: <202206171941.25HJf7Wx030058@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: d573cf010ead - stable/13 - linux(4): Add a helper to copyout getsockopt value 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d573cf010ead8d66c72fb8544ceee151128b5bf5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494868; 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=BRvEH6/S3Q6tnaFj0IaC/OrOvkI501OnySRVd37KRnQ=; b=vsOQUomwUdsXU0BK0VEUWnuJbZH7wamFz7m5RgFyhlz7CF+61Cleq8VhQqqCQ9S2XXWtVh U0jtZH1XOhEx8Ryi6IwQka57JS/pcQtW0PeKrMsULLz1zcJIvS6kUwhdiwA2Qkk/+V4UzK H2D5oEd0gBT4TGOcN3Zg/QOqz9YY5iBoKWsFTdmMrcasRWChybKb0NbYrZNr/ucSc45Snw 1t6EVNzZEy6ywWrONtBrRsov93xz5Y6gmILAFqjYDQf9dnY0A2XhWkuJOLPUxs4LpyQXaT zmjA0G6Mp8lQPzxmZya4kbP30pqIQ04IlRubCv5Vv/C9oEjVFE4k9O06kg0BCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494868; a=rsa-sha256; cv=none; b=l7XC/1dN8J93r6AfygGCnWBAvO9tol8j6MsSCv3KtFyHj7/6MoS00xX/KvQz1ExKge8S9Q LfnNK0TwkuFgmKoe+5tHYQUq6nSiqOU+ME76KhdLUtfrFXUEM32KdM56EoUDj0kNT1gsrZ Rk7fO7gJbeEgGFQIgL0TG+F4jvSYcWvhYRTzOqqQnAZLqiXz2jsBmvr3rtZwVZr2Z5YXe/ i6rzJ0ZpugxMcXs1nYKFiyV8Ca95fbbPal6Qurt7RXIPnRe0M/9viWP3u5E7qF6F57SGx+ O6KA+NbBKbCwKwRlE1TwWpEwUeVxMnbL+WxwgJRbaoIPi2JiL1Y+urjxxMF2xg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=d573cf010ead8d66c72fb8544ceee151128b5bf5 commit d573cf010ead8d66c72fb8544ceee151128b5bf5 Author: Dmitry Chagin AuthorDate: 2022-05-28 20:30:22 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:32 +0000 linux(4): Add a helper to copyout getsockopt value For getsockopt(), optlen is a value-result argument, which is modified on return to indicate the actual size of the value returned. For some cases this was missed, fixed. MFC after: 2 weeks (cherry picked from commit e92b9a9eaa646bc1037af2a838270c43ea607d55) --- sys/compat/linux/linux_socket.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 8aa425bc14c0..0c003cd5729f 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1924,6 +1924,18 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args) return (error); } +static int +linux_sockopt_copyout(struct thread *td, void *val, socklen_t len, + struct linux_getsockopt_args *args) +{ + int error; + + error = copyout(val, PTRIN(args->optval), len); + if (error == 0) + error = copyout(&len, PTRIN(args->optlen), sizeof(len)); + return (error); +} + static int linux_getsockopt_so_peergroups(struct thread *td, struct linux_getsockopt_args *args) @@ -1976,13 +1988,11 @@ linux_getsockopt_so_peersec(struct thread *td, return (error); } - error = copyout(SECURITY_CONTEXT_STRING, - PTRIN(args->optval), sizeof(SECURITY_CONTEXT_STRING)); - if (error == 0) - error = copyout(&len, PTRIN(args->optlen), sizeof(len)); - return (error); + return (linux_sockopt_copyout(td, SECURITY_CONTEXT_STRING, + len, args)); } + int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) { @@ -2021,8 +2031,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) return (error); linux_tv.tv_sec = tv.tv_sec; linux_tv.tv_usec = tv.tv_usec; - return (copyout(&linux_tv, PTRIN(args->optval), - sizeof(linux_tv))); + return (linux_sockopt_copyout(td, &linux_tv, + sizeof(linux_tv), args)); /* NOTREACHED */ case LOCAL_PEERCRED: if (args->optlen < sizeof(lxu)) @@ -2040,7 +2050,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) lxu.pid = xu.cr_pid; lxu.uid = xu.cr_uid; lxu.gid = xu.cr_gid; - return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu))); + return (linux_sockopt_copyout(td, &lxu, + sizeof(lxu), args)); /* NOTREACHED */ case SO_ERROR: len = sizeof(newval); @@ -2049,7 +2060,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) if (error != 0) return (error); newval = -bsd_to_linux_errno(newval); - return (copyout(&newval, PTRIN(args->optval), len)); + return (linux_sockopt_copyout(td, &newval, + len, args)); /* NOTREACHED */ case SO_DOMAIN: len = sizeof(newval); @@ -2060,7 +2072,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args) newval = bsd_to_linux_domain(newval); if (newval == -1) return (ENOPROTOOPT); - return (copyout(&newval, PTRIN(args->optval), len)); + return (linux_sockopt_copyout(td, &newval, + len, args)); /* NOTREACHED */ default: break;