Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4874458rdb; Fri, 15 Sep 2023 15:23:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYskpjGLSXgdtjeuaJFBGuBJMdoEq74muanOOuYmn+wFLuOLyUkw+Rds7INK7CgHdm9tVv X-Received: by 2002:a05:6a20:7288:b0:153:6a8b:8f5b with SMTP id o8-20020a056a20728800b001536a8b8f5bmr3502668pzk.54.1694816601957; Fri, 15 Sep 2023 15:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694816601; cv=none; d=google.com; s=arc-20160816; b=00BN0N6omQ/aqgUEI07hlZjeML6v7+Spe5YlF20xspfb/SFqkvGtr8pBhiFW34S6o/ M3EgjekkLFMkK0xD56Jb+Wz1R5CCeMqHo2tPxYOcKq2dBZJwUa1V854UIrPor02fsm39 osnz88zhl3DJjhyBuqmZatKFHj+7Ep+GptEGDuvFvasDGbnF2P8Lab1A7oifNFyKZ/QH bTFMYG6HQ934Q920XB2ojRJHsvzfJJRGc4NVZmeXLQe62Y8+OaSV7meio9Z0lsuOpJpf jgeaSS/wUeSbaI7gnFyVNEL4U35AwcTWHd6M8vxLnNBicw0txZFEk+fjDLIbhbHXM+89 Fx2Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=DD0PB0X4P5RpnzepdYBK20P6YgyKEeTbO8VvW3SzPE0=; fh=/xTWh0s80eOG9ONK/bth6D2DoiKDrVvMib/441QoiBE=; b=jTF+403ZvvGFmZCACS5tvqUwVz8S4MjHTkyDb5bX8Z7I1TaTh3DvVn52yaH2byfV0I Mg1Q5SS03Th9kf/eF6YL5jkJ3M02aOk+x0Zy0vfM6qb358wDL9aNz/P1+rStvnDpODhJ T9kNV7/XQE0SwlRrVoOufQUnydFnsg6geHgbkyxgYJciiCViQ6hqyG1JRp2drbT3I1B2 1t+P2h8Idx2AwKGFdEciqYByvCk5fLuADK9WPQHxSWtNYu/oc4eClJVbcIhj9NiQGMXD 9zUDZL04oBavF9Vmrv2jQt8cPosNHr1MZiRwir0cqp97TdsY5uK9BC/KbZEgINZ7HAkV yfrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bj9GANvp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l65-20020a633e44000000b0056417c8a310si1372224pga.204.2023.09.15.15.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bj9GANvp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1E1C7828EC37; Fri, 15 Sep 2023 13:17:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237246AbjIOUQP (ORCPT + 99 others); Fri, 15 Sep 2023 16:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237383AbjIOUP6 (ORCPT ); Fri, 15 Sep 2023 16:15:58 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F372D67 for ; Fri, 15 Sep 2023 13:15:13 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c337aeefbdso23591845ad.0 for ; Fri, 15 Sep 2023 13:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694808912; x=1695413712; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DD0PB0X4P5RpnzepdYBK20P6YgyKEeTbO8VvW3SzPE0=; b=bj9GANvp8YMMDuzcyMnE4zefjLBFuDD33Jq2y3Phwq7y9R7lwZIczNSCqX4LThWcOJ 9Khb33XoLSMbUtZdO4wfd5q2Lw9YSy5Df2WV5q8aYt8f0ZwUulF2JbFrucv2Q/e8E689 +oCl9AIiLj3uEQFpgJZkCDRVN/JRnzz86fj2o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694808912; x=1695413712; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DD0PB0X4P5RpnzepdYBK20P6YgyKEeTbO8VvW3SzPE0=; b=RS7DSWI6VLiClN7TPxMEoLC/k2rJb6oxwJPbg4piPDbbvO8CqwU96J6HtOPnYm0fJN qCbRhEH6C5uiDyGkZkUCtZOXxZi1UsLw7BAshs7EwaRc4Ok4unqbsq6qh9du+UjPJ5E0 6uJuufPd9Hrvp30H2WvBDtOxDcDTB5d1z3hbhk2A2XimHUNk6gbtjBpEwgp60UIgAs0J 34XA3USfaSbSpxW7J3J1SPq3L+9OPdnhquYPXKIhQc6c//u3U0s52915RXF8s62qj2rr bzLH0k1zCQWImqRvalE4Ent2sTtYFdO8c0ZYL/n7bfWfskjWNywiGXzpdSEKJI239KNg GMBw== X-Gm-Message-State: AOJu0YznuPtOZ8B9nXQzpHjKnYW9Cr4Le0QehkMrVEShHQ6afAdinCKb MgEONULAImcyt4iHtU8EexILGg== X-Received: by 2002:a17:902:dac7:b0:1bf:4582:90d with SMTP id q7-20020a170902dac700b001bf4582090dmr3499033plx.46.1694808912608; Fri, 15 Sep 2023 13:15:12 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u5-20020a170902b28500b001bb750189desm3860366plr.255.2023.09.15.13.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:15:12 -0700 (PDT) From: Kees Cook To: Ilya Dryomov Cc: Kees Cook , Xiubo Li , 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 Subject: [PATCH] ceph: Annotate struct ceph_monmap with __counted_by Date: Fri, 15 Sep 2023 13:15:10 -0700 Message-Id: <20230915201510.never.365-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2263; i=keescook@chromium.org; h=from:subject:message-id; bh=459xt744zpKd86AyMgpOkR51nqx31Cb+Bg+uK/o0T7M=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlBLtO5BRclquwJun9hzXP0EWlZ+GoTdZhGJ3lG aGjx/Zz1HyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQS7TgAKCRCJcvTf3G3A JsmGEACL2A1XKUQWibswLmpq3EltVpG/A8eKgv6ea2LwVOAXy0x4SXG4cHd9Cu0nk/qHBUbSafm /LRlD5lO/9C+ATYOdVAn9t0V3au/VIjn21sAW1gMsSMXTEBt4RYva6+8ekRrcCE6zJyxKRcZ8FV 1TP0oLZ+aZEmq83/afsOUMhAKZ73EU1YJrP2y7qEuhd9AasIKJxUVGM7DVcfrya6r/JmudEniQ/ slYEzs/iOWTdsEj98u6gHbxVZWi3l4+Z2chqEOmaA47jYTbgLzIPmPYPYPcWB1kjzGWo7sTENSL snWzCkLtSJUMzl4dC2P8qEjNTs9Z97Zfy+yyMAePSR5RQLGtIWKXITcZgFCekUIF7vLjevaPaV1 +LaCKf+sOzA2EWId/vEIG/kxz8h8dHLkrY/QRUmyY/uVFzbwLiOZE7DHTIBX2RKoIZGZEJUzBeR WNBaLF/w+lrRYldhG58wFjnEbGbgvVMya2tw0RpvwrbwceT8tHUcSV7MEFW5AduNfn/W80+XcU3 WDRvge5QEdCUPgTXx/dF6CwMbzLuJM8bVq/JMoDpnZhUBciUwbOy/Mj2aVFC17+IUS36d5chuol RHp8X04Aun56SGx2HOl8Y46SbRFH50UsjBo4xWwVLeRAjb1uW/Qjq7Ps3DWovxlJ5RdT/+l0n1p IJga5Lu zADa1NNA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:17:04 -0700 (PDT) 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; return 0; } -- 2.34.1