From owner-svn-src-all@freebsd.org Fri Jul 19 15:24:09 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 44F80A56A7; Fri, 19 Jul 2019 15:24:09 +0000 (UTC) (envelope-from ae@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2782B7298B; Fri, 19 Jul 2019 15:24:09 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DA21B22F48; Fri, 19 Jul 2019 15:24:08 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6JFO8qI063414; Fri, 19 Jul 2019 15:24:08 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6JFO84W063413; Fri, 19 Jul 2019 15:24:08 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201907191524.x6JFO84W063413@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Fri, 19 Jul 2019 15:24:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r350138 - stable/11/sys/netpfil/ipfw X-SVN-Group: stable-11 X-SVN-Commit-Author: ae X-SVN-Commit-Paths: stable/11/sys/netpfil/ipfw X-SVN-Commit-Revision: 350138 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 2782B7298B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.966,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jul 2019 15:24:09 -0000 Author: ae Date: Fri Jul 19 15:24:08 2019 New Revision: 350138 URL: https://svnweb.freebsd.org/changeset/base/350138 Log: MFC r349940: Correctly truncate the rule in case when it has several action opcodes. It is possible, that opcode at the ACTION_PTR() location is not real action, but action modificator like "log", "tag" etc. In this case we need to check for each opcode in the loop to find O_EXTERNAL_ACTION. Obtained from: Yandex LLC Sponsored by: Yandex LLC MFC r349941: Do not modify cmd pointer if it is already last opcode in the rule. Modified: stable/11/sys/netpfil/ipfw/ip_fw_eaction.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/netpfil/ipfw/ip_fw_eaction.c ============================================================================== --- stable/11/sys/netpfil/ipfw/ip_fw_eaction.c Fri Jul 19 15:17:54 2019 (r350137) +++ stable/11/sys/netpfil/ipfw/ip_fw_eaction.c Fri Jul 19 15:24:08 2019 (r350138) @@ -377,35 +377,51 @@ ipfw_reset_eaction(struct ip_fw_chain *ch, struct ip_f uint16_t eaction_id, uint16_t default_id, uint16_t instance_id) { ipfw_insn *cmd, *icmd; + int l, cmdlen; IPFW_UH_WLOCK_ASSERT(ch); IPFW_WLOCK_ASSERT(ch); cmd = ACTION_PTR(rule); + l = rule->cmd_len - rule->act_ofs; + while (l > 0) { + cmdlen = F_LEN(cmd); + l -= cmdlen; + if (cmd->opcode == O_EXTERNAL_ACTION || l <= 0) + break; + cmd += cmdlen; + } + /* + * Return if there is not O_EXTERNAL_ACTION or its id is + * different. + */ if (cmd->opcode != O_EXTERNAL_ACTION || cmd->arg1 != eaction_id) return (0); - - if (instance_id != 0 && rule->act_ofs < rule->cmd_len - 1) { + /* + * If instance_id is specified, we need to truncate the + * rule length. Check if there is O_EXTERNAL_INSTANCE opcode. + */ + if (instance_id != 0 && l > 0) { + MPASS(cmdlen == 1); icmd = cmd + 1; if (icmd->opcode != O_EXTERNAL_INSTANCE || icmd->arg1 != instance_id) return (0); - /* FALLTHROUGH */ + /* + * Since named_object related to this instance will be + * destroyed, truncate the chain of opcodes to remove + * the rest of cmd chain just after O_EXTERNAL_ACTION + * opcode. + */ + EACTION_DEBUG("truncate rule %d: len %u -> %u", + rule->rulenum, rule->cmd_len, rule->cmd_len - l); + rule->cmd_len -= l; + MPASS(((uint32_t *)icmd - + (uint32_t *)rule->cmd) == rule->cmd_len); } cmd->arg1 = default_id; /* Set to default id */ - /* - * Since named_object related to this instance will be - * also destroyed, truncate the chain of opcodes to - * remove the rest of cmd chain just after O_EXTERNAL_ACTION - * opcode. - */ - if (rule->act_ofs < rule->cmd_len - 1) { - EACTION_DEBUG("truncate rule %d: len %u -> %u", - rule->rulenum, rule->cmd_len, rule->act_ofs + 1); - rule->cmd_len = rule->act_ofs + 1; - } /* * Return 1 when reset successfully happened. */