Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3415186rwa; Tue, 23 Aug 2022 04:31:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Gi9QVxWMCFlzjznvrtRvIHZp/XbCc3jsDvDW+mTOhuhJE872hgLHRghhouO9Y4wOCWOSG X-Received: by 2002:a17:902:8309:b0:170:8c4e:e2c3 with SMTP id bd9-20020a170902830900b001708c4ee2c3mr24370797plb.171.1661254199906; Tue, 23 Aug 2022 04:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254199; cv=none; d=google.com; s=arc-20160816; b=nF55OS1AAN6kauGem72bRzY6qsNm//QWnZziasw/N+ahCWDwXeIQClntV7OKpcFk3U ZJFeXX0Ftc6q6L9yffOkjU0WgGAlr/gPy1uHpgZWfCHdzfAgi6AuSPKdQtwzaQyJjSvQ 5UoypqpUNBb1QiZmRyww43BDwnUVL99sZ0Xz/yDkZ4MKYRn+7//zE6fmmelwbrsYs04D mg+nJXkBDWuhCiKoRv4pyi3WcUblC+azxcTO0d6ykuJoOfmyopQqxas/c19xoy11/N/r XO22uqrEEQbLVv4vJY1qB2yA1HSXcCiotY6JSTiCnVnTo1gQpd1kNN9hhSB2gCnaHzlc KKZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eHWiC76U5NASHnjfUpNxGFUMr02ELGzE8NYqobNgdqA=; b=dEJcGbCWcWYFm9zT0luU7epUGi64av1ZGLeYH5MyHJzKXjCNpcvP5cwsQKwncxQ7if bSRMx351pnG69poEokzCgYIaYiKVVz+sEP+rCrw9Z3U5c4AwriKTS3EXuKuxShdjw9fO yfSc3AcJcOhiNITgVEUgpSSSQoxXqRHhwVJ9wihJCCWXKHSCmQZ2qJ0to92Rp/s+M1oy A2J1CzY2lUVkV4v/IJyoIIBU8OQ5sTYN3bahH2EmevjHXQpAHv1GmMTzMpbmwdb3iWaa i41xUY0HzL8H52PhEA0kQlJ9yqs2aBzaKqnVYuzO2olOV+MbfxysDpfaHkKSUlRnuSle lphw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tz0e6Pba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iz15-20020a170902ef8f00b0016f9420a15asi13574302plb.168.2022.08.23.04.29.48; Tue, 23 Aug 2022 04:29:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tz0e6Pba; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242379AbiHWJ7T (ORCPT + 99 others); Tue, 23 Aug 2022 05:59:19 -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: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luís 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ís 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 = FEATURE_BYTES(count); + unsigned long bit; if (WARN_ON_ONCE(*p + 4 + size > end)) return -ERANGE; ceph_encode_32(p, size); memset(*p, 0, size); - for (i = 0; i < count; i++) - ((unsigned char*)(*p))[i / 8] |= BIT(feature_bits[i] % 8); + for (i = 0; i < count; i++) { + bit = feature_bits[i]; + ((unsigned char *)(*p))[bit / 8] |= BIT(bit % 8); + } *p += 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 = CEPHFS_FEATURE_METRIC_COLLECT, }; -/* - * 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 {}