Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5930521rdb; Sun, 17 Sep 2023 20:25:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQnrU8MZeIVVDta6x6aeFdcxUP01msgcuQNgWk114FZLV5CwfjVUR/9u90RFokS6Uis8/B X-Received: by 2002:a05:6870:ec92:b0:1d6:4641:9172 with SMTP id eo18-20020a056870ec9200b001d646419172mr7901431oab.48.1695007555673; Sun, 17 Sep 2023 20:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695007555; cv=none; d=google.com; s=arc-20160816; b=A2D6VvJ63mm8GaqdTFq0vKNbO2UHjhkVpWSp4Mbae0FjB7FVHoqotGWfirQXqYRQZw njChXqxOu/h7WMOsEOcdCyACIIEUfQvYyRsyuNVMb4I3cZCqPeihKfYn6dZ6gXF4nDe7 jbiOGnUFYi0BFIiVmLiwdN7iAXqEVMmbZiRE5YuolYEdsnT1WrnIDgETDHkpTednUq2x sQgdiJ0dOBrvNfT/DODTtsHSP2oSRxzDCVrhz/ca73rfLR703cH5EIAAmyvQbBnxN+1Y sDReu0nfixbDoULjgZ38WP54JYgh8GWzjG/RXFmpYoEE1X/RrRBoZnylJI8ztPd6wCe7 OEkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7XGw7AdgYIk+RoEKFj7VSzvf+HqUpChJVq9bKRl2ets=; fh=0RmAs5SybgGu29dFsn+T7YwgWJUyPYERfh7h7mkTTTc=; b=cMIdYWZkoZhOZuO+WJi2j8BEagM6mXM0oeX9/FgcIPqG6z36BOCrF8KoJ5dtWHH9BA ieXg5q/ZlE1J9+dyiUfasvh3IUFUDO1bM0b4CgbKcSFgXE7ADKzpWUt8BXVwcIg8HB80 MjF3ylbAvscYV4uo7a1e9n6bAk/e/UAAT+z9bQeXgDWXkgp9mmcd3A0FVMQveMXwSMpO 47BkmC+urJlJq0vh81K4J5AG010WmWuCqRgPk8PYmuai203OpC8GLBNU8nI41ZFRCypP MCp16JDGbQDz07PHi64hssIuOq43jGdZB/T6b3x9njPNmFueI98WothuPdBdGJPujxKj i9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TkntXe/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id r9-20020a17090aa08900b0026d05caaa58si9226002pjp.123.2023.09.17.20.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 20:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TkntXe/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D2ECA81D68E3; Sun, 17 Sep 2023 17:28:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233433AbjIRA0d (ORCPT + 99 others); Sun, 17 Sep 2023 20:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232544AbjIRA0M (ORCPT ); Sun, 17 Sep 2023 20:26:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62A8A126 for ; Sun, 17 Sep 2023 17:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694996719; 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=7XGw7AdgYIk+RoEKFj7VSzvf+HqUpChJVq9bKRl2ets=; b=TkntXe/5AJ6EcuDQjCYYViIbwcnK/MBFNMSSdiCVWUc+bbkdlekPwWfuveoaScnDg8LMvr VUdigkqby0j95ULeF2Fg+FM4WXsGCG/Kbcv1X0wRcXVT4p2ogpaDVqQbArce8poBZ00rMN a2z0nyLq2EVfWfImwJKVPaIrUfS4NAI= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-NcLhw3YiPu65IJ2kV8t1Eg-1; Sun, 17 Sep 2023 20:25:17 -0400 X-MC-Unique: NcLhw3YiPu65IJ2kV8t1Eg-1 Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-780addd7382so376973539f.1 for ; Sun, 17 Sep 2023 17:25:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694996717; x=1695601517; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7XGw7AdgYIk+RoEKFj7VSzvf+HqUpChJVq9bKRl2ets=; b=p+P4OqgwNT3aQR8DDTEWqlbVXtcK1GwMO+Wk37eGcLbcKBLW1m1hJlxic5VMS7N740 /v7SVx/Erfy9WBVXSUrp9kZmQwwN3San/8njprC03BiPwvMCg19M5c+LNcehtegUk0id EvF36CZXq3LkJnnYRR56PlcKt3j6KTXPN+VjUAvedafVwZtcRWl3kUauY9FEpsl7g+Z8 YS+GjIahWefoj9Yn4QxI5JEotbYENEBizwF9ZyrqbXR8rjBwG4lTKMwuJRG01gGDX9xt C3FWFt+wdQ/M9GiZanzeJnoMkcSYIOKdUSfdtFjyPwN+3ugwblktgRvn4OrR1oxXAnLq CVPQ== X-Gm-Message-State: AOJu0Ywz/7mOGFdeeMJQjuivDrWzjVEzhPSGMCOL/peFvchMkDbaPRe/ Mbc6RNwQaJcNfpe1m7hz5U0ql167LU4LzF2Q+Mftlmo8Ubkqbx3RxWpIa71AudCqVUDkOz3neNF k79utv1fBW6pgijFpkLBcJOxT X-Received: by 2002:a92:c243:0:b0:34f:f373:ad7e with SMTP id k3-20020a92c243000000b0034ff373ad7emr465804ilo.1.1694996716962; Sun, 17 Sep 2023 17:25:16 -0700 (PDT) X-Received: by 2002:a92:c243:0:b0:34f:f373:ad7e with SMTP id k3-20020a92c243000000b0034ff373ad7emr465795ilo.1.1694996716745; Sun, 17 Sep 2023 17:25:16 -0700 (PDT) Received: from [10.72.113.158] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id m23-20020a635817000000b0056606274e54sm4393724pgb.31.2023.09.17.17.25.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Sep 2023 17:25:16 -0700 (PDT) Message-ID: <3c4c7ca8-e1a2-fbb1-bda4-b7000eb9a8d9@redhat.com> Date: Mon, 18 Sep 2023 08:25:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] ceph: Annotate struct ceph_monmap with __counted_by Content-Language: en-US To: Kees Cook , Ilya Dryomov Cc: Jeff Layton , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , ceph-devel@vger.kernel.org, netdev@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org References: <20230915201510.never.365-kees@kernel.org> From: Xiubo Li In-Reply-To: <20230915201510.never.365-kees@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 17 Sep 2023 17:28:04 -0700 (PDT) On 9/16/23 04:15, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct ceph_monmap. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Ilya Dryomov > Cc: Xiubo Li > Cc: Jeff Layton > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: ceph-devel@vger.kernel.org > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > include/linux/ceph/mon_client.h | 2 +- > net/ceph/mon_client.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/ceph/mon_client.h b/include/linux/ceph/mon_client.h > index b658961156a0..7a9a40163c0f 100644 > --- a/include/linux/ceph/mon_client.h > +++ b/include/linux/ceph/mon_client.h > @@ -19,7 +19,7 @@ struct ceph_monmap { > struct ceph_fsid fsid; > u32 epoch; > u32 num_mon; > - struct ceph_entity_inst mon_inst[]; > + struct ceph_entity_inst mon_inst[] __counted_by(num_mon); > }; > > struct ceph_mon_client; > diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c > index faabad6603db..f263f7e91a21 100644 > --- a/net/ceph/mon_client.c > +++ b/net/ceph/mon_client.c > @@ -1136,6 +1136,7 @@ static int build_initial_monmap(struct ceph_mon_client *monc) > GFP_KERNEL); > if (!monc->monmap) > return -ENOMEM; > + monc->monmap->num_mon = num_mon; > > for (i = 0; i < num_mon; i++) { > struct ceph_entity_inst *inst = &monc->monmap->mon_inst[i]; > @@ -1147,7 +1148,6 @@ static int build_initial_monmap(struct ceph_mon_client *monc) > inst->name.type = CEPH_ENTITY_TYPE_MON; > inst->name.num = cpu_to_le64(i); > } > - monc->monmap->num_mon = num_mon; BTW, is this change related ? > return 0; > } > Else LGTM. Reviewed-by: Xiubo Li Thanks! - Xiubo