From owner-freebsd-bugs@freebsd.org Wed Aug 15 10:39:51 2018 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 395D0107D3BD for ; Wed, 15 Aug 2018 10:39:51 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id E879D846C9 for ; Wed, 15 Aug 2018 10:39:50 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id AA6D0107D3B0; Wed, 15 Aug 2018 10:39:50 +0000 (UTC) Delivered-To: bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 88ACE107D3AB for ; Wed, 15 Aug 2018 10:39:50 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0A9DA846C2 for ; Wed, 15 Aug 2018 10:39:50 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 27FBF235D3 for ; Wed, 15 Aug 2018 10:39:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id w7FAdnop056342 for ; Wed, 15 Aug 2018 10:39:49 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id w7FAdnvk056341 for bugs@FreeBSD.org; Wed, 15 Aug 2018 10:39:49 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 230640] pf_map_addr operates on unlocked src_nodes and pools Date: Wed, 15 Aug 2018 10:39:47 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 11.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: vegeta@tuxpowered.net X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Aug 2018 10:39:51 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D230640 Bug ID: 230640 Summary: pf_map_addr operates on unlocked src_nodes and pools Product: Base System Version: 11.2-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: vegeta@tuxpowered.net Created attachment 196212 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D196212&action= =3Dedit Fix locking issues around pf_map_addr. I came across the following issues with pf_map_addr: - It operates on unlocked src_nodes and I've seen kernel crashes attributab= le to this. - For route-to targets which specify outgoing interface, interface selection happens outside of pf_map_addr and can be taken from different redirection target than was used for IP address selection. - Hash used for locking and unlocking src_node is calculated multiple times= for same src_node. - Operations on rule->pool are unlocked, there even is a comment in code mentioning circumstances where it can cause kernel crash. I attached a patch addressing those issues. Please note it is early version= , it compiles, it runs, I'm not sure if it is really correct. The patch does the following: - Struct pf_pool has a lock now. Round-robin algorithm in pf_map_addr locks= the pool. Other algorithms don't do it, I don't think they need. Should we also have table operations check this lock? - pf_find_src_node does not manipulate src_node's state counter. It is a "f= ind" function so why would it manipulate other stuff? Also with new location of sn->states++ removing of unused src_node in pf_create_state will work, I'm pretty sure it was broken before. - pf_insert_src_node returns locked. The lock is retained across pf_create_state and pf_map_addr. - pf_insert_src_node returns hash (row) of locked src_node. It is used later for unlocking without recalculating the hash. - Interface chosen by pf_map_addr is assigned to external variable from wit= hin this function. Struct src_node stores the interface. --=20 You are receiving this mail because: You are the assignee for the bug.=