From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B7C6C433ED for ; Thu, 13 May 2021 17:08:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 752776141B for ; Thu, 13 May 2021 17:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbhEMRJn (ORCPT ); Thu, 13 May 2021 13:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbhEMRJk (ORCPT ); Thu, 13 May 2021 13:09:40 -0400 Received: from orbyte.nwl.cc (orbyte.nwl.cc [IPv6:2001:41d0:e:133a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74BC9C06175F; Thu, 13 May 2021 10:08:27 -0700 (PDT) Received: from n0-1 by orbyte.nwl.cc with local (Exim 4.94.2) (envelope-from ) id 1lhEow-00029d-BN; Thu, 13 May 2021 19:08:22 +0200 Date: Thu, 13 May 2021 19:08:22 +0200 From: Phil Sutter To: Pablo Neira Ayuso Cc: Dexuan Cui , "'netfilter-devel@vger.kernel.org'" , "'netdev@vger.kernel.org'" , Stephen Hemminger , Haiyang Zhang , "'linux-kernel@vger.kernel.org'" Subject: Re: netfilter: iptables-restore: setsockopt(3, SOL_IP, IPT_SO_SET_REPLACE, "security...", ...) return -EAGAIN Message-ID: <20210513170822.GA3673@orbyte.nwl.cc> Mail-Followup-To: Phil Sutter , Pablo Neira Ayuso , Dexuan Cui , "'netfilter-devel@vger.kernel.org'" , "'netdev@vger.kernel.org'" , Stephen Hemminger , Haiyang Zhang , "'linux-kernel@vger.kernel.org'" References: <20210513094047.GA24842@salvia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210513094047.GA24842@salvia> Sender: Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Hi, On Thu, May 13, 2021 at 11:40:47AM +0200, Pablo Neira Ayuso wrote: > On Thu, May 13, 2021 at 06:19:38AM +0000, Dexuan Cui wrote: > > > From: Dexuan Cui > > > Sent: Wednesday, May 12, 2021 11:02 PM > > > > BTW, I found a similar report in 2019: > > > > " > > https://serverfault.com/questions/101022/error-applying-iptables-rules-using-iptables-restore > > I stumbled upon this issue on Ubuntu 18.04. The netfilter-persistent > > service failed randomly on boot while working ok when launched manually. > > Turned out it was conflicting with sshguard service due to systemd trying > > to load everything in parallel. What helped is to setting > > ENABLE_FIREWALL=0 in /etc/default/sshguard and then adding sshguard chain > > and rule manually to /etc/iptables/rules.v4 and /etc/iptables/rules.v6. > > " > > > > The above report provided a workaround. > > There's -w and -W to serialize ruleset updates. You could follow a > similar approach from userspace if you don't use iptables userspace > binary. My guess is the xtables lock is not effective here, so waiting for it probably won't help. Dexuan, concurrent access is avoided in user space using a file-based lock. So if multiple iptables(-restore) processes run in different mount-namespaces, they might miss the other's /run/xtables.lock. Another option would be if libiptc is used instead of calling iptables, but that's more a shot in the dark - I don't know if libiptc doesn't support obtaining the xtables lock. > > I think we need a real fix. > > iptables-nft already fixes this. nftables (and therefore iptables-nft) implement transactional logic in kernel, user space automatically retries if a transaction's commit fails. Cheers, Phil