From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9638A3A2560 for ; Fri, 27 Mar 2026 06:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774593185; cv=none; b=QyZGnTV69gAgLHeF4D+CTcQE7XTyONCHY8g2oYOvF9MyPjdubTOJ6SN9RICh6EoO0Zx0K45PzzZF8l7D2FCxF7ObODX5iIIsfenSTrP98db3QqZ3EbbEtomTPowthILWdgM0XUA8gPiNSzCXad6j3zZBHIQab4pVt4ce3vlXcmc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774593185; c=relaxed/simple; bh=R+Wyx2quThKO6kdxp3NboLSs48m1AeEp3SSFm3vLIIk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OhFcPC1ItaUQKa6JcjYMtcXCUQ/YGNRjUbXKwA8XDL2AWpZDHVbbh+0bsHtl+WBu93vIUmrLIUVNLtOmPpzn7ixvEQXLLmSGnpUkAKarI/ew7pSDf5Noquc1GpdzZi4RVMpIPk+rKKfuH/YgkNBDYmzi+MwTTk1FQn68GLwe2og= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L7bGfVKf; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L7bGfVKf" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ab08e6c553so1309375ad.3 for ; Thu, 26 Mar 2026 23:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774593173; x=1775197973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NYhDafFa6ifxo2/1PziNZDy5gbmYZ4I4QcjogoZ5uUc=; b=L7bGfVKf5H6+UJk+J+qFOYg/U0GF6J2FQhf6p07IRZH3sJxY/URQScJ4FV1xVHI4wN Tum9VElXlV56xaVrQPhdJcuIqO5duuQYI7yYfkqIJv3QdI+cCjeVKeQoJTkLj01SYOfx g6JIl8eazA/Nu2tva0QeJmMug/UatZgSth4HPmdihe3GGRFFRjKuoMcz3lsXAUGLXdQF iOjYev1Srf0IbPh6/84P8luMgrDx79syDsCr0x1hvhxiD44iX5RPs7Wf1Qn4BhRazDzZ Gj2N20O3KtMIK+uyDvCTFN0HRKShEA7v+BNz0p3L7j3Ha9RakGMvNKZShepMGk/aP1Mq 38EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774593173; x=1775197973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NYhDafFa6ifxo2/1PziNZDy5gbmYZ4I4QcjogoZ5uUc=; b=ImALcOKlzdybSq8UFZAoztD1APJ/3J8p5FZExKcVDnb/wDfrXj9H9LzNQKzoIzIgYC WTb9UVvkV+MnpZuQ+Ts1HNAAfdAOOM9h9XV0qnbDwHK26jNc0SS4pfaV/EeFsQcX3sqw T3zEfXocDiHoVTCO6EYuUu7hKICrsdklmTwKp/1Xncj53+HntFpuOyT6zydOO/C5jLRY pfZwJlbIdiVwFFLb+hIJi0Lnge1w7orLpR6k3w/nbS8pl9sSIwOc/CaPBrakLKVBGlQQ pERpNJVrce/D4Um1BfAec3MQpI6JrlJndsmOhRaxYZk+o7v1KZl33gB6E4aJubNo1pWY pOLw== X-Forwarded-Encrypted: i=1; AJvYcCV4iW6Pd03BkUxL1+CWgLqUrBobT+WhL+MOWucvg1M4uRzqS2xC5X7OfhdzIYP6sPhiVL2m6vgcx/D2B/0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0pLHBPCZsND3a+uavdKsKYJ+I6ZqnrKU2257t0LiUFfOLEKkJ Vd6e99f8gZ8JKgmKNG8pGGqs7nrQjJVwTVsgG53/NxLuEN5c6BsYhLhX X-Gm-Gg: ATEYQzzvP+wbJOY1HBKjeEnYNJ9jYGRVSHz2WNqEr2pCQc6hTxe4vAwllxaOEizBKkr nxkzwHdw50C7QA3GlbiEfB/YbG5NPr4wlHWnOvebRarYLFxO4QMML8IXl8DNAFIXCBDYHzLfkcS E4jvPgZbso4zcndToqwsVsvCibQi2+g6HPTOdPiSLaFrhuNdfryU+mWnhrP+4aaBFcFNnbGNCPa VqLx6g00ZuWn2+XriSJwD4kZdSPSy0tCiKrTKL6YQoNadVxEIZsV3XxOJmYWSqXktHi4H3iYiD8 pTULSlW50H3D3zXWWu0tBjsbjYTIg9qNe4hPHQl8XS9iDJ1jhIU3EbvuTZaOV7Luy290AC6VL02 3zu0a0FBjnYhZceeRCD/P6xfgacB+f09OWpDWWDO8hg5EIYVbh2IEbrd5hRbK+KokbSNElgEJwC jzc5zoJURS1jTczQXbdx4ExtAbLX0z2F0l X-Received: by 2002:a05:6a00:2da3:b0:82a:68e4:da90 with SMTP id d2e1a72fcca58-82c95ee3d68mr849669b3a.4.1774593171986; Thu, 26 Mar 2026 23:32:51 -0700 (PDT) Received: from localhost.localdomain ([189.1.242.96]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82c7d3bedeesm4498146b3a.42.2026.03.26.23.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 23:32:51 -0700 (PDT) From: sunichi To: i.maximets@ovn.org Cc: aconole@redhat.com, davem@davemloft.net, dev@openvswitch.org, echaudro@redhat.com, edumazet@google.com, horms@kernel.org, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, sunyiqixm@gmail.com Subject: Re: Re: [PATCH] net/openvswitch: fix trigger-able BUG_ON after ovs_vport_cmd_fill_info Date: Fri, 27 Mar 2026 14:32:27 +0800 Message-Id: <20260327063227.2069909-1-sunyiqixm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <3813e7fb-e234-42ec-b05c-7bcb609de3ba@ovn.org> References: <3813e7fb-e234-42ec-b05c-7bcb609de3ba@ovn.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On 3/24/26 1:01 PM, Ilya Maximets wrote: > On 3/23/26 8:14 AM, sunichi wrote: > > ovs_vport_set_upcall_portids() does not validate the length of the > > user-supplied OVS_VPORT_ATTR_UPCALL_PID netlink attribute. A > > sufficiently large portid list can overflow the reply skb allocated > > with NLMSG_DEFAULT_SIZE in causing ovs_vport_cmd_fill_info() > > to return -EMSGSIZE and triggering the unconditional BUG_ON(), > > which panics the kernel on most distributions. > > > > Any local user with CAP_NET_ADMIN (or an equivalent unprivileged > > namespace capability where applicable) can exploit this to perform a > > denial-of-service against the host. > > > > Replace BUG_ON with WARN_ON_ONCE to prevent kernel panic. > > > > Signed-off-by: sunichi > > --- > > net/openvswitch/datapath.c | 17 ++++++++++++----- > > 1 file changed, 12 insertions(+), 5 deletions(-) > > > > diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c > > index e209099218b4..50c2945081a1 100644 > > --- a/net/openvswitch/datapath.c > > +++ b/net/openvswitch/datapath.c > > @@ -2202,7 +2202,8 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net, > > > > retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd, > > GFP_KERNEL); > > - BUG_ON(retval < 0); > > + if (WARN_ON_ONCE(retval < 0)) > > + return ERR_PTR(-EMSGSIZE); > > Hi, sunichi. Thanks for the patch! Though I don't think this is the right > solution. Instead of just failing the request, we should allocate appropriate > amount of memory for it instead. The fact that the array is sort of unbounded > today is also a problem. > > So, what I'd suggest is, let's limit the number of upcall pids for a vport with > the number of CPUs as it is done for the upcall_pids array on the datapath level. > This will give us some reasonable upper value as there is no point for the > application to have more handlers than there are CPUs, and the existing userspace > never does that, so the limit should be safe. Next we can create a new function > ovs_vport_cmd_msg_size() similar to the existing ovs_dp_cmd_msg_size() that would > calculate and allocate the appropriate message size, so the allocation is always > correct. Thanks for the detailed review, Ilya! Agreed on all points. For v2 patch submit later, would: 1. Add ovs_vport_cmd_msg_size() to calculate the correct allocation size upfront, eliminating the EMSGSIZE path entirely. 2. Fix the memory leak on the error path. > P.S.: This patch also needs a Fixes tag and should be targeted for the 'net' > tree, i.e. have [PATCH net] as a subject prefix. Also, IIRC, kernel requires > a full name in the sign-off tag. > > AI review also points out a memory leak in case we just return without freeing > and potentially leaving half- or even fully configured port while returning an > error to the userspace. > > Best regards, Ilya Maximets. > Respectfully, sunichi.