From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE02F19BC5 for ; Wed, 7 Jun 2023 20:34:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E8DBC4339B; Wed, 7 Jun 2023 20:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686170064; bh=BlFXP6Y74txutFxdgw9/CuM0Oc1b1LPiP2VuEmnZcPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1odY/5C4oy313tQtZlKwfat2gJkPAaG5oXiCcMlrNAe6LUh4TY3oGKMiBwP/mBBdt e+FKv4r3MDpegmmdq2qTRKZXZG1KC9l2djplii88drHQ7HQr/Xp0IXNMNPiv0SXdua T6UZmoDIp6PTmYvgo2loZoTUXBFTnFFq69eGfh30= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pedro Tammela , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 24/88] net/netlink: fix NETLINK_LIST_MEMBERSHIPS length report Date: Wed, 7 Jun 2023 22:15:41 +0200 Message-ID: <20230607200859.796089377@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230607200854.030202132@linuxfoundation.org> References: <20230607200854.030202132@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Pedro Tammela [ Upstream commit f4e4534850a9d18c250a93f8d7fbb51310828110 ] The current code for the length calculation wrongly truncates the reported length of the groups array, causing an under report of the subscribed groups. To fix this, use 'BITS_TO_BYTES()' which rounds up the division by 8. Fixes: b42be38b2778 ("netlink: add API to retrieve all group memberships") Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman Link: https://lore.kernel.org/r/20230529153335.389815-1-pctammela@mojatatu.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/netlink/af_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index c73784b7b67dc..57fd9b7cfc75f 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1775,7 +1775,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, break; } } - if (put_user(ALIGN(nlk->ngroups / 8, sizeof(u32)), optlen)) + if (put_user(ALIGN(BITS_TO_BYTES(nlk->ngroups), sizeof(u32)), optlen)) err = -EFAULT; netlink_unlock_table(); return err; -- 2.39.2