From nobody Sat May 28 20:53:17 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 497021B479FE; Sat, 28 May 2022 20:53:18 +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 4L9YmF6t9sz4kqc; Sat, 28 May 2022 20:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653771198; 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=0kycKkEJMdIGbOwVUPZl2ccQKOQTcdE2l7+SAu+QCog=; b=bTzOzbXuD7MkXtPHBlEsaqhYWaol0YI6ksRPARMcIqD2LmhLRMwNsqJs2FY3kVw8uwhNyz MUlyhaUfV+fMuo8NadrhB5tpsO8nLxVdFCIyI9vRj4vTLnrirR9IOyYov47m31kMqBjnbT vXaunGlYaFN1GONcnNyHk9Tze9InBBPVdoDF+5fVFLcuvYArJPnx0ISO0aPxYCqrgJcPHE oTT5JphjcrCJuXfk+V8sTrpVsBUhI19myeD6EohUn5MBwqYCT4CWafoC1UnViSTph3pC9N eS8/43DulkYCm+QHyO49DLxnVMrgx9rQXQ2ADEFv5wUU0JH3GFAnKvwfFC29tA== 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 82F331603E; Sat, 28 May 2022 20:53:17 +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 24SKrHVV099258; Sat, 28 May 2022 20:53:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24SKrHNF099257; Sat, 28 May 2022 20:53:17 GMT (envelope-from git) Date: Sat, 28 May 2022 20:53:17 GMT Message-Id: <202205282053.24SKrHNF099257@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: e92b9a9eaa64 - main - linux(4): Add a helper to copyout getsockopt value 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e92b9a9eaa646bc1037af2a838270c43ea607d55 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653771198; 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=0kycKkEJMdIGbOwVUPZl2ccQKOQTcdE2l7+SAu+QCog=; b=INWoLU1uRchjmUBDP7Q8whRIP7CPfEq2bwffcT+XbvXbV/NRUlyX6quNyhExwY6gFidLbJ NpT6+m+lEVr3STqcbGTjlGaq+SbEN+0MSj6HgncPn/RirIFXGEPUjiW/JyaLPheO26zNtA eiQdqzSPt6Bq9fU8KAGYs7T9Xephq4oS41xO5Lhz3IjebWodmVU/J6wmswBVMfCs7mLBkC PDbBM8UC3MktPkTID45o4WW7LaG+qgdc4bGoNFnGuI60qXQFKREw4jOK1gFvDMYMArOUpD VtQkm1SS+wn5jiwjsQ0O1vKx89u91f0d39K4peGHrj9oA0xQtIrqGFTvi+Aegw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653771198; a=rsa-sha256; cv=none; b=hzTxTDZUhB3ZZYxBmoJHm/U5La0aZlgOksVmeIxfyFs2RUWdDdpSWU7wQPdLUageExkUXe 357eGpnrMFl1kYPaCgZwEkLjLOtz9nhoruvMCtdc8fqda8rMh0WNFAkmH5VXQDYyv230kQ yhGVh4TSZJ/lkVYVtswuMlHQ/XR9psmCReskTEmjbvYybcyzrIFpaiSvHqMBytxHcqANQw vYgGZGr5QmhjVIxxYtkZQkrTc6D0XUxHi0mmdc+tlE5yK7ehQyqwqPfDL9lZ8NfXzATFyK 1LpSd8MKQVskGt4aZcBHzT6tTL+za7jE/S84+22Tj+bt0HAb64mjEYlmDEPs4A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e92b9a9eaa646bc1037af2a838270c43ea607d55 commit e92b9a9eaa646bc1037af2a838270c43ea607d55 Author: Dmitry Chagin AuthorDate: 2022-05-28 20:30:22 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-28 20:30:22 +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 --- 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;