From nobody Tue May 17 14:00:38 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 C5ABB1ADCFF4; Tue, 17 May 2022 14:00:38 +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 4L2d7B5GT3z4Z96; Tue, 17 May 2022 14:00:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652796038; 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=zLrgYzbQnTQgle0TjfNC17mEUrvDAEkGsk/7CCOYVSE=; b=nhCNYWHzk6eETDWuEvPJNnKd4tqRpA35cw3NLfm7D26mdwr2Z4lZY5H/3qFsctCZdxIxZV siJvf71AtWtK662UiotsqqYc6L2FLOc6abYtLNRQgb11To3pC0aMXGq2wuKfhxfEOLDRnz JIMHd7HPqc81bOUj/TlA5VbyGQXFKSKrvB81fEXSUhnJwgNxefZD2WOatCV03pY4jLiXD/ ktFBIf9kgsp1zoyhMLTdTJ5gEWOo5cTHX1/Q+UkfweQVxUs/APujT0AUj0lmbJgVu5wXGj LJ8sP6as+mtgNPKpqynviBATyg+dyVlG52JAH3cvBZH329zkq4Bna3hn8qRZmw== 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 95735160B9; Tue, 17 May 2022 14:00:38 +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 24HE0cW0038699; Tue, 17 May 2022 14:00:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24HE0cVZ038698; Tue, 17 May 2022 14:00:38 GMT (envelope-from git) Date: Tue, 17 May 2022 14:00:38 GMT Message-Id: <202205171400.24HE0cVZ038698@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 386b1a033c4d - main - pf: allocate krule->timestamp in pf_krule_alloc() 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 386b1a033c4d7345efd378b47cb637d4fb709020 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652796038; 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=zLrgYzbQnTQgle0TjfNC17mEUrvDAEkGsk/7CCOYVSE=; b=boE6SRlpg7TGIffhbq7RKFqmpizrkVqZTNOKttBIujvN5kgEqjw7+JSmmbvdIF4BWRiCsD VXyS5fo6XfUOIC0KbAWLdSuDLOGTqwfLtjd2PW8eNzpyXGmnhRiF7CklaAPAvRc2Ui+ER0 eBj/HrS6xSfzV+pjlVGarCxOvqPFgl320svSn7LYaU17EwA+DJd6ob+29G4H/qd5n1YsIF yzsrCmJb5K4khMXf2g8XVVlr0jriyrcPscdfVwQrGWrbwfh17OyQkF+Y4sOch7Y5gTgtor /7ECF1C7zg/kJeUqDJoMqjOuM6BE9owi84tdQwwvHWmlyRYEmJYm0vWIh6Vw4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652796038; a=rsa-sha256; cv=none; b=DjPwu8pf2U1i2onao1AXLdRz+VhOXh9T3aCkDbcyst8zEtXigi/S0+Ty/ZOM2vyq6YGt7I BGfXzczzxRF8aiT/GyxsnZC6tHEWVXDtNYSiAz2u23B6TU5zQdcLdIplTrIlTwWU5fG3VM 69LRdpPQ332pq99Z2pie/NwYkqesKu53WgypO3H+QlK22HbhVKcFio24x6eu1nFuylOpbN WPqohjFuuabqfNMNgJObL1lJWEtFO8GEU4aJUP2DWIVpBH+USNtuBgazYh6+mJJExahHVw Pd7mxdHqXk192uOmp88h77l/UdNBSnfMXsu3JlVN2uo5qSD5DyHLxLTuCg5EDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=386b1a033c4d7345efd378b47cb637d4fb709020 commit 386b1a033c4d7345efd378b47cb637d4fb709020 Author: Kristof Provost AuthorDate: 2022-05-17 12:41:25 +0000 Commit: Kristof Provost CommitDate: 2022-05-17 13:55:08 +0000 pf: allocate krule->timestamp in pf_krule_alloc() There are three calls which can allocate a new rule. DIOCADDRULE, DIOCADDRULENV and DIOCCHANGERULE. The first two call pf_ioctl_addrule(), but DIOCCHANGERULE does not. As a result rules created through DIOCCHANGERULE do not have the timestamp per-cpu memory allocated, and we panic when the rule is exported with pf_krule_to_nvrule(). Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 8c3b9a423af1..5185e457867e 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1771,6 +1771,7 @@ pf_krule_alloc(void) rule = malloc(sizeof(struct pf_krule), M_PFRULE, M_WAITOK | M_ZERO); mtx_init(&rule->rpool.mtx, "pf_krule_pool", NULL, MTX_DEF); + rule->timestamp = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO); return (rule); } @@ -2134,7 +2135,6 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket, rule->states_cur = counter_u64_alloc(M_WAITOK); rule->states_tot = counter_u64_alloc(M_WAITOK); rule->src_nodes = counter_u64_alloc(M_WAITOK); - rule->timestamp = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO); rule->cuid = td->td_ucred->cr_ruid; rule->cpid = td->td_proc ? td->td_proc->p_pid : 0; TAILQ_INIT(&rule->rpool.list); @@ -3412,7 +3412,7 @@ DIOCGETRULENV_error: newrule = pf_krule_alloc(); error = pf_rule_to_krule(&pcr->rule, newrule); if (error != 0) { - free(newrule, M_PFRULE); + pf_krule_free(newrule); break; }