From nobody Mon Jan 30 16:29:05 2023 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 4P5DCQ0Xp6z3bssc; Mon, 30 Jan 2023 16:29:06 +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 4P5DCP6qdXz484h; Mon, 30 Jan 2023 16:29:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675096146; 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=H2MgovSiesW5OSVVQssk5E8/06NCb7SICnWVWgImwnI=; b=xy2fPqf/DmGsqGgSs/pvysGhjYK57UXzZcuBTrM/SM8wJzBOhsbcvleCEZ64rMf/YcLvAE cU6vCTYKshjH5BALnkZNJgVcZ/rx7Wpw2ToqpkNqtkFaVJoqYi7rCySeT+qNZzNb/1F9oM u7mvQ/gg4nh4HNUl9IdTEr+nRzI/UL8hPS5izul0OLpU0P60F+Ns+r8T4dgqrvCGq7+2RK tCdb1jU7zQAqIwDmIWWUWOh4kzA0W7yDcGeamSnS/E1huZtvMOeh1ZH4u5DvCBTgPcseUx UvSUJn7od0+eTq8s6U4MDdLueen6VyrWyeFYDME2V41+45baEK/eg8rMry4Ykg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675096146; 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=H2MgovSiesW5OSVVQssk5E8/06NCb7SICnWVWgImwnI=; b=QQxp/CHfEXNzGEgpNCz2yCa/uD6brP4YCixLXkkI3sxpbZDnIegQWrZoqKrtinEzONJnXJ Bcuu7nD38mZdc72fltHKqNp1rF1c7Qr5sJgw27SxTKGSYv58Nv+6TXNh3CUHboaEXMgR4H tZzDiO0xt/+Wd5f6zTHgQgqruIVemgCtiyi67AgyF0C29AsHTONuHljuoftekpPYRnInWu 5PhY98raFCkB9uqtzkOWx9F2cb53u3pwFvTz58tctpMRWq2iOZQXIvFNXuayj2UNZCS67v 17fvjy3JkJgF3Sia5YgBhMnG1zEAiBHTKDoO51h/Ud8y6U+8oJ1J3xrjeY3piQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675096146; a=rsa-sha256; cv=none; b=xmLRdtIeYTd+Ayldt1PyaQs2G1xkBo+gzmzkJtCX5pztEAl3y+WPldoj98CjeGFq2nOqeI lBFlnvskZ2I7J2rUfgA6MXL0Tk+bWvBDcN9+A2ix3iBkAzz1iyWdqpoRE0Eu19d8yz9XtO cUUY/1SYTZQs3uDYy2JUTStuOEDE0YPfyHrP+IzQI58YxHUSUL0vyl/vwMiEmV0fqnCYS/ 3YLWz/eMBwceZTubKiQU/NjSDztp4VdLfKEhDsEalIbjdt0uZqIP7Z5EDy6XvfG3ZEI5px 7LakQ+fJNHa3I/IjyU6oADwvFTa6uINHfbF7cqLwtA9PNLm16XVyuIcpewDzPA== 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 4P5DCP5tmtzFgj; Mon, 30 Jan 2023 16:29:05 +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 30UGT5a8061280; Mon, 30 Jan 2023 16:29:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30UGT5Gd061279; Mon, 30 Jan 2023 16:29:05 GMT (envelope-from git) Date: Mon, 30 Jan 2023 16:29:05 GMT Message-Id: <202301301629.30UGT5Gd061279@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: 2058f075b4af - main - cpuset: Handle CPU_WHICH_TIDPID wherever cpuset_which() is called. 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: 2058f075b4afc543b8735599bea7278e37b2e9f9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=2058f075b4afc543b8735599bea7278e37b2e9f9 commit 2058f075b4afc543b8735599bea7278e37b2e9f9 Author: Dmitry Chagin AuthorDate: 2023-01-30 16:28:54 +0000 Commit: Dmitry Chagin CommitDate: 2023-01-30 16:28:54 +0000 cpuset: Handle CPU_WHICH_TIDPID wherever cpuset_which() is called. cpuset_which() resolves the argument pair which and id and returns references to an appropriate resources. To avoid leaking resources or accessing unresolved references to a resources handle new which CPU_WHICH_TIDPID wherever cpuset_which() is called. To avoid code duplication cpuset_which2() has been added. Reported by: syzbot+331e8402e0f7347f0f2a@syzkaller.appspotmail.com Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D38272 MFC after: 2 weeks --- sys/kern/kern_cpuset.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index ba0a15b86e01..894d29ea1ac8 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -150,6 +150,8 @@ SYSCTL_UINT(_kern_sched, OID_AUTO, cpusetsizemin, cpuset_t *cpuset_root; cpuset_t cpuset_domain[MAXMEMDOM]; +static int cpuset_which2(cpuwhich_t *, id_t, struct proc **, struct thread **, + struct cpuset **); static int domainset_valid(const struct domainset *, const struct domainset *); /* @@ -988,6 +990,20 @@ cpuset_which(cpuwhich_t which, id_t id, struct proc **pp, struct thread **tdp, return (0); } +static int +cpuset_which2(cpuwhich_t *which, id_t id, struct proc **pp, struct thread **tdp, + struct cpuset **setp) +{ + + if (*which == CPU_WHICH_TIDPID) { + if (id == -1 || id > PID_MAX) + *which = CPU_WHICH_TID; + else + *which = CPU_WHICH_PID; + } + return (cpuset_which(*which, id, pp, tdp, setp)); +} + static int cpuset_testshadow(struct cpuset *set, const cpuset_t *mask, const struct domainset *domain) @@ -1902,6 +1918,7 @@ kern_cpuset_getid(struct thread *td, cpulevel_t level, cpuwhich_t which, switch (which) { case CPU_WHICH_TID: case CPU_WHICH_PID: + case CPU_WHICH_TIDPID: thread_lock(ttd); set = cpuset_refbase(ttd->td_cpuset); thread_unlock(ttd); @@ -1963,7 +1980,7 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, error = cpuset_check_capabilities(td, level, which, id); if (error != 0) return (error); - error = cpuset_which(which, id, &p, &ttd, &set); + error = cpuset_which2(&which, id, &p, &ttd, &set); if (error != 0) return (error); switch (level) { @@ -2006,19 +2023,6 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, thread_unlock(ttd); } break; - case CPU_WHICH_TIDPID: - if (id > PID_MAX || id == -1) { - thread_lock(ttd); - CPU_COPY(&ttd->td_cpuset->cs_mask, mask); - thread_unlock(ttd); - break; - } - FOREACH_THREAD_IN_PROC(p, ttd) { - thread_lock(ttd); - CPU_OR(mask, mask, &ttd->td_cpuset->cs_mask); - thread_unlock(ttd); - } - break; case CPU_WHICH_CPUSET: case CPU_WHICH_JAIL: CPU_COPY(&set->cs_mask, mask); @@ -2138,6 +2142,7 @@ kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, switch (which) { case CPU_WHICH_TID: case CPU_WHICH_PID: + case CPU_WHICH_TIDPID: thread_lock(ttd); set = cpuset_ref(ttd->td_cpuset); thread_unlock(ttd); @@ -2283,7 +2288,7 @@ kern_cpuset_getdomain(struct thread *td, cpulevel_t level, cpuwhich_t which, return (error); mask = malloc(domainsetsize, M_TEMP, M_WAITOK | M_ZERO); bzero(&outset, sizeof(outset)); - error = cpuset_which(which, id, &p, &ttd, &set); + error = cpuset_which2(&which, id, &p, &ttd, &set); if (error) goto out; switch (level) { @@ -2475,6 +2480,7 @@ kern_cpuset_setdomain(struct thread *td, cpulevel_t level, cpuwhich_t which, switch (which) { case CPU_WHICH_TID: case CPU_WHICH_PID: + case CPU_WHICH_TIDPID: thread_lock(ttd); set = cpuset_ref(ttd->td_cpuset); thread_unlock(ttd); @@ -2506,6 +2512,13 @@ kern_cpuset_setdomain(struct thread *td, cpulevel_t level, cpuwhich_t which, case CPU_WHICH_PID: error = cpuset_setproc(id, NULL, NULL, &domain, false); break; + case CPU_WHICH_TIDPID: + if (id > PID_MAX || id == -1) + error = _cpuset_setthread(id, NULL, &domain); + else + error = cpuset_setproc(id, NULL, NULL, &domain, + false); + break; case CPU_WHICH_CPUSET: case CPU_WHICH_JAIL: error = cpuset_which(which, id, &p, &ttd, &set);