From nobody Mon Feb 6 19:07:52 2023 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 4P9bPN6V1Pz3n466; Mon, 6 Feb 2023 19:07:52 +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 4P9bPN5tx6z3QWZ; Mon, 6 Feb 2023 19:07:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710472; 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=3tl/bQ3B5X2ry1Q2xSowgWn6rcE2r0f/3dx7sXgKE4s=; b=xyFhkX6NtbIBcG92zyXG05fXm40DAU2HrV4NgtFkYLXLCP3DIr2xgPhn+EUJqRiXfeF0jC kM2BC+YdxIwJ/tCLnZzC005toeFEbvFjco/DqNkiCKEMd6FrarWttC8fy9NxVC35bpq3L9 WzNh+7a271wChz3Zym33MAozQyudnaQLiXctHqKP1bfPf9p7s6EumXU8IOp3hpOb0tQCOP AIit6LFWqn2rdAkojttdwaFw6LmB1eJlzgd5YiY3lclJG7sNgW8gEeUDPWPplvU9ZqxV9E CimnmtHNQ12gzZBpJBanLWs16/Lutq0XrHFvcshvDWzzw43P4bNjFRW6PyGUKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710472; 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=3tl/bQ3B5X2ry1Q2xSowgWn6rcE2r0f/3dx7sXgKE4s=; b=fQRwaF3R6bYfRNEPMSdhOFZXhXiVnwzvSO4uLVabvW3/+haoNOT7Tjk9hlTsxgeMvHAcB1 iQIsc+Pb/Fr3kO3/OQJ6jpo/yEBEedJc7FAu9CPIMXFDJgZa02QwQ7c8WBWIbZS9fpo6bQ Avdo9z5GBAJrKczygHm8BYS2m2M9nnwXdUPtQaY5KZuVtdkDI50+CYkwygTYPCON2y6JHp CZ7RYba9PcHvx+9O2AajYhNJXXsqDbZvvTOdjqbGqUqboQYggloTH5qdkgFDkPvvxBFDvn Ei4yHQphtzVjtKRKmiDC6JlXBTRpy16HUw8kzAWCMcO5hjuxrfFYcWQn1GCRKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675710472; a=rsa-sha256; cv=none; b=UVTc34whr8BlZwoNDqRuojY7XD9aZuq0FTZfmd9nJtWloGgASmEaBdCFKtxWREPv3g8DgD 6HpLIDl/MopeK9L9SGU7WhzOXmgqARFibjiDvzEDuhR0nku2ot4NZ4DJZEz9OHGozaEOf5 TrWzFMsLyxYReLCyoAMWcyf6HH1lEFDyF2qIOdOtLP2co7lNjOYlZDlrKhlgXJCPo7MkC0 0QjCLvm6kd9mxQXNZ7EHUoPlbnc8rNOFG8R8w+pBGwnSP4Vee1ptWyhVySzPbJ/qFKHquw HYsH2YLcTuajh4cg6RHNV4qzoCcbj17Ps8irxP61s5rLJ6Xht2pB8gac3TVGcQ== 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 4P9bPN50VyzmWK; Mon, 6 Feb 2023 19:07:52 +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 316J7qBh077061; Mon, 6 Feb 2023 19:07:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 316J7q2N077060; Mon, 6 Feb 2023 19:07:52 GMT (envelope-from git) Date: Mon, 6 Feb 2023 19:07:52 GMT Message-Id: <202302061907.316J7q2N077060@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: 11ade1dffc8d - stable/13 - cpuset: Handle CPU_WHICH_TIDPID wherever cpuset_which() is called. 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: 11ade1dffc8dbdcf2541b2f9b2da61a998ccafc7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=11ade1dffc8dbdcf2541b2f9b2da61a998ccafc7 commit 11ade1dffc8dbdcf2541b2f9b2da61a998ccafc7 Author: Dmitry Chagin AuthorDate: 2023-01-30 16:28:54 +0000 Commit: Dmitry Chagin CommitDate: 2023-02-06 19:06:31 +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 (cherry picked from commit 2058f075b4afc543b8735599bea7278e37b2e9f9) --- 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 1c8fa09cc224..dfc32d01295e 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);