From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id C3D925A026D for ; Tue, 19 Mar 2024 12:00:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710846013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WmNazpAga1MxmY0dfVdxWYSeaiA6/xcWEWPSOhsgkKg=; b=HXkufK/v15gd/OiInWOFsSGYUG2cDdMQIP6Rs9z13or8sBAqD/kS/TV9vcaPEQiBFIEjg8 QRWryupNMZEDaFRKtxbIhifWI3fKQBOvi1dkcjR+c3+Ep0k3x+1swXrEIXtII9F3Yb79eI zLU3etQe9I+K1cwMaFBT6wSMHSqcuLY= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-3SOniXDyOaWAS3c1oCfnNw-1; Tue, 19 Mar 2024 07:00:12 -0400 X-MC-Unique: 3SOniXDyOaWAS3c1oCfnNw-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-513eee2dca5so1526434e87.0 for ; Tue, 19 Mar 2024 04:00:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710846010; x=1711450810; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WmNazpAga1MxmY0dfVdxWYSeaiA6/xcWEWPSOhsgkKg=; b=rpukOmFUzF5rVjLLMitZzyDzBPvctHXvBHI9docR7DmfwGicy7SzzE8csBAoICNqi3 DWyAPxtFNUVuOrjrAZFlr+44SpgQsIDpf0N1gSrB6sJjz+p8cfKNWrAiskIGf0EDPjZ8 T8EuZWKe/mcLt7zsTYHXsb8dCPXwq6QUqs0fGU1G3+Wf7dJETrLFf1jazDMwC3B9N39x +PSgGBIcibNj4AW+VjzDscNuRWP91+KjDgx1xyoarLBzLC4Ln4RhSlewOjSmHP/GiKnL hGzAEHKy8WUNEEj/4C7cF2MwMAUSSIoo11fUIzRQr6o4MLkw8TuFVZNblp7wd7uFr4hS /BCQ== X-Gm-Message-State: AOJu0YyHqseWhXl8d2zwAm1sIblEsO7Tiqg3npvx9HSAlaXyJik11M+H l9eJPV/myPV+KaCB5KLlJeOIBR0JKaz9DVNoUyTQrt5PgTkFu+wguniQTvH/1oUf0QCBe3+RjJt NBxvk9F+OASk9JagU2oYInuGT7RfKks1mYG15WIx5i2wFTnbn7A== X-Received: by 2002:ac2:4c37:0:b0:513:5c10:309c with SMTP id u23-20020ac24c37000000b005135c10309cmr1758687lfq.3.1710846010500; Tue, 19 Mar 2024 04:00:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfcF3/h8yGmQUFmBfqQZ5LiTY5f5gvTek1Bvh0L0kZPjo5mTcT54nrNCzD6I7MFVLBTxPRsg== X-Received: by 2002:ac2:4c37:0:b0:513:5c10:309c with SMTP id u23-20020ac24c37000000b005135c10309cmr1758653lfq.3.1710846009909; Tue, 19 Mar 2024 04:00:09 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id h12-20020a170906260c00b00a457a55b814sm5986899ejc.73.2024.03.19.04.00.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Mar 2024 04:00:09 -0700 (PDT) Date: Tue, 19 Mar 2024 11:59:27 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH] netlink: Fix handling of NLMSG_DONE in nl_route_dup() Message-ID: <20240319115927.363b0d53@elisabeth> In-Reply-To: <20240319045341.487396-1-david@gibson.dropbear.id.au> References: <20240319045341.487396-1-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: TEFQHXR2ZVJAFGXCFXUEXMJ2T63LWGER X-Message-ID-Hash: TEFQHXR2ZVJAFGXCFXUEXMJ2T63LWGER X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, mpitt@redhat.com, pholzing@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 19 Mar 2024 15:53:41 +1100 David Gibson wrote: > A recent kernel change 87d381973e49 ("genetlink: fit NLMSG_DONE into > same read() as families") changed netlink behaviour so that the > NLMSG_DONE terminating a bunch of responses can go in the same > datagram as those responses, rather than in a separate one. > > Our netlink code is supposed to handle that behaviour, and indeed does > so for most cases, using the nl_foreach() macro. However, there was a > subtle error in nl_route_dup() which doesn't work with this change. > f00b1534 ("netlink: Don't try to get further datagrams in > nl_route_dup() on NLMSG_DONE") attempted to fix this, but has its own > subtle error. > > The problem arises because nl_route_dup(), unlike other cases doesn't > just make a single pass through all the responses to a netlink > request. It needs to get all the routes, then make multiple passes > through them. We don't really have anywhere to buffer multiple > datagrams, so we only support the case where all the routes fit in a > single datagram - but we need to fail gracefully when that's not the > case. > > After receiving the first datagram of responses (with nl_next()) we > have a first loop scanning them. It needs to exit when either we run > out of messages in the datagram (!NLMSG_OK()) or when we get a message > indicating the last response (nl_status() <= 0). > > What we do after the loop depends on which exit case we had. If we > saw the last response, we're done, but otherwise we need to receive > more datagrams to discard the rest of the responses. > > We attempt to check for that second case by re-checking NLMSG_OK(nh, > status). However in the got-last-response case, we've altered status > from the number of remaining bytes to the error code (usually 0). That > means NLMSG_OK() now returns false even if it didn't during the loop > check. To fix this we need separate variables for the number of bytes > left and the final status code. > > We also checked status after the loop, but this was redundant: we can > only exit the loop with NLMSG_OK() == true if status <= 0. > > Reported-by: Martin Pitt > Fixes: f00b153414b1 ("netlink: Don't try to get further datagrams in nl_route_dup() on NLMSG_DONE") > Fixes: 4d6e9d0816e2 ("netlink: Always process all responses to a netlink request") > Link: https://github.com/containers/podman/issues/22052 > > Signed-off-by: David Gibson Applied. -- Stefano