From nobody Sat Sep 27 20:22:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09480C32772 for ; Tue, 23 Aug 2022 09:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239885AbiHWJ7V (ORCPT ); Tue, 23 Aug 2022 05:59:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347534AbiHWJzm (ORCPT ); Tue, 23 Aug 2022 05:55:42 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 506739FAB7; Tue, 23 Aug 2022 01:46:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 06FC5CE1B44; Tue, 23 Aug 2022 08:46:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C4E9C433D6; Tue, 23 Aug 2022 08:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244405; bh=idwXDovuJudcRH2ebDa2NMriVeD5uSVEG3fLcuZQ+s0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tz0e6PbaZ4NyO34N0Ocuiwzql/cb9L0GJFqLUPkI+yndZGlRofULCX13eOln5JYn4 u7zbrejoZmk7wozAzHlyd6jFP9V2S/KXZTDiWNxFmqyXaVj/p6wN/oSSJevR2FpwEa vcrd+3cG0HyEZi1bRE6WSxIsz5FKq1s7/XlJymX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Lu=C3=ADs=20Henriques?= , Jeff Layton , Xiubo Li , Ilya Dryomov Subject: [PATCH 5.15 089/244] ceph: use correct index when encoding client supported features Date: Tue, 23 Aug 2022 10:24:08 +0200 Message-Id: <20220823080101.995858671@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu=C3=ADs Henriques commit fea013e020e6ecc7be75bea0d61697b7e916b44d upstream. Feature bits have to be encoded into the correct locations. This hasn't been an issue so far because the only hole in the feature bits was in bit 10 (CEPHFS_FEATURE_RECLAIM_CLIENT), which is located in the 2nd byte. When adding more bits that go beyond the this 2nd byte, the bug will show up. [xiubli: remove incorrect comment for CEPHFS_FEATURES_CLIENT_SUPPORTED] Fixes: 9ba1e224538a ("ceph: allocate the correct amount of extra bytes for = the session features") Signed-off-by: Lu=C3=ADs Henriques Reviewed-by: Jeff Layton Signed-off-by: Xiubo Li Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/mds_client.c | 7 +++++-- fs/ceph/mds_client.h | 6 ------ 2 files changed, 5 insertions(+), 8 deletions(-) --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1196,14 +1196,17 @@ static int encode_supported_features(voi if (count > 0) { size_t i; size_t size =3D FEATURE_BYTES(count); + unsigned long bit; =20 if (WARN_ON_ONCE(*p + 4 + size > end)) return -ERANGE; =20 ceph_encode_32(p, size); memset(*p, 0, size); - for (i =3D 0; i < count; i++) - ((unsigned char*)(*p))[i / 8] |=3D BIT(feature_bits[i] % 8); + for (i =3D 0; i < count; i++) { + bit =3D feature_bits[i]; + ((unsigned char *)(*p))[bit / 8] |=3D BIT(bit % 8); + } *p +=3D size; } else { if (WARN_ON_ONCE(*p + 4 > end)) --- a/fs/ceph/mds_client.h +++ b/fs/ceph/mds_client.h @@ -33,10 +33,6 @@ enum ceph_feature_type { CEPHFS_FEATURE_MAX =3D CEPHFS_FEATURE_METRIC_COLLECT, }; =20 -/* - * This will always have the highest feature bit value - * as the last element of the array. - */ #define CEPHFS_FEATURES_CLIENT_SUPPORTED { \ 0, 1, 2, 3, 4, 5, 6, 7, \ CEPHFS_FEATURE_MIMIC, \ @@ -45,8 +41,6 @@ enum ceph_feature_type { CEPHFS_FEATURE_MULTI_RECONNECT, \ CEPHFS_FEATURE_DELEG_INO, \ CEPHFS_FEATURE_METRIC_COLLECT, \ - \ - CEPHFS_FEATURE_MAX, \ } #define CEPHFS_FEATURES_CLIENT_REQUIRED {} =20