Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6589643pxv; Thu, 29 Jul 2021 19:31:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvh/MHvy/ldoWkWrspIsMPjZwUOiG7EVwUf0oZ82czohhTPMdyjyQr66H3ctvcTfKv+43y X-Received: by 2002:a05:6402:291a:: with SMTP id ee26mr243532edb.220.1627612306700; Thu, 29 Jul 2021 19:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627612306; cv=none; d=google.com; s=arc-20160816; b=AVlJR4XNfezHjp6VjZMCedjBm2Vuc0QhBYMGgeUOYPCrAj3gJqPov74C/x5umb0C6m f1AF3+eeoKFvrtvefq3PKqpRdTzoymz0Ec42ha5cYP6c9iSZS/cHmsU/+Tws5Y9wrCf5 sR/v65fOu5DKsn1BQlPIXrgrGP/17KqSob6EDUdEjgH3GJz3SdVbqfio4kBkwIbFZy7/ DrDhR2cpDJKnXOLlhENybi5Ijcj50GUqMOQ7bPchSCHzItFlRYNBf5L/zPHMLvhfp2Av Hzmr1Kqq4xr0xH4Ft89EjlNMdATBPPSFTNCg+MdrNqSHF41FzLIWGcYRdSdVxGaWptqh XkVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fUqZ0NLVZxg4yvCXyE1lEs/e7e2cakQ+3GgW8pZJCvA=; b=EzuPrSgD2W4dMutP7psWSPFmbFcGcOuDBjN5ZR0uyVT06gXg2jw9ySbVqFKI1hliWp NGFl13/m/+pY4EmpFRAVoyGxV3c6uRXdYOV6n8eG5dZIDlzno2lyCEgutwnDh3kuPFQ1 4xBIWva0Jz/fI6T0aBYlwvGow983GodJWXzMUOjlnvmReHp00pslMdWpVaZ6FlrT5DrG hTzQq595qAtXDXzd6AYm6gq/UxbYBGHYFIreCRhnJH4XiuH/bGOKQCErbZPob8mg2r63 /W0GIKZtmhSMGXuVeSuU0s35gc3VEqBBIjkaalnc35PBiq3T2BCW3+thQqPvJpsc5/lN gFYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=etYre1Aj; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si281629eds.417.2021.07.29.19.31.16; Thu, 29 Jul 2021 19:31:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=etYre1Aj; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235518AbhG3CbP (ORCPT + 99 others); Thu, 29 Jul 2021 22:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235295AbhG3CbO (ORCPT ); Thu, 29 Jul 2021 22:31:14 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B6FC061796 for ; Thu, 29 Jul 2021 19:31:10 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id n10so9281971plf.4 for ; Thu, 29 Jul 2021 19:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fUqZ0NLVZxg4yvCXyE1lEs/e7e2cakQ+3GgW8pZJCvA=; b=etYre1AjERNhjyVA/9+2+oLRj921sU45jCtD5h5fRrioHVxndRb/wVYqd+Gvs/9PWN W5TIwCrEKVrSomZp1XNcHMR3yLthFd9Qftp86Ybrvy7SLYwhXBueLu90Yc4ejQUhYSOC pE6uT73BOuVftlnSqfS6+2EzGpdU+4QF+7NHo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fUqZ0NLVZxg4yvCXyE1lEs/e7e2cakQ+3GgW8pZJCvA=; b=JrXEWOHmSQv/eI8rcp50TSyw9o8NFsw8n64prbTfTa5pZux9aoblDtg6tHHkZ1CB4i Vhj1v0+I3uAPYXoZkY6Qz1lIA/p+NjFg0/zxleBie2tWRC4y1b09s+UieboiM1scE6fE fBRDKUy5+2qVLw49lKIY7sZ3iUnr+pQFdKmKrB0S0qp53uZrWUyihp+KqTO/Sqmj1Api tdw+N0DtDWk5A7M0GubzgTBGkz7gXambDrScBAJRUO7LfP1N4sz+rYO39afKcvlsVLNF V0s9r2f0Ow3WCQTmzvIABL+vbWDiYiR/ZyyZvMR5vulhMJoo2IlMTB8YTl06PqiOEGv/ SVZw== X-Gm-Message-State: AOAM531hjHHF0s8J3Rx0qRQtQb7WNLtkZ2jRivE7ZN0W1D+nixUsMpfJ OH0aqRYMbmNeUOAoBzk9C/9c3g== X-Received: by 2002:a05:6a00:168a:b029:2fb:6bb0:aba with SMTP id k10-20020a056a00168ab02902fb6bb00abamr526959pfc.32.1627612270101; Thu, 29 Jul 2021 19:31:10 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q13sm218718pjq.10.2021.07.29.19.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 19:31:09 -0700 (PDT) Date: Thu, 29 Jul 2021 19:31:08 -0700 From: Kees Cook To: Bart Van Assche Cc: linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" , Keith Packard , Greg Kroah-Hartman , Andrew Morton , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH 48/64] drbd: Use struct_group() to zero algs Message-ID: <202107291845.1E1528D@keescook> References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-49-keescook@chromium.org> <1cc74e5e-8d28-6da4-244e-861eac075ca2@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1cc74e5e-8d28-6da4-244e-861eac075ca2@acm.org> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, Jul 28, 2021 at 02:45:55PM -0700, Bart Van Assche wrote: > On 7/27/21 1:58 PM, Kees Cook wrote: > > In preparation for FORTIFY_SOURCE performing compile-time and run-time > > field bounds checking for memset(), avoid intentionally writing across > > neighboring fields. > > > > Add a struct_group() for the algs so that memset() can correctly reason > > about the size. > > > > Signed-off-by: Kees Cook > > --- > > drivers/block/drbd/drbd_main.c | 3 ++- > > drivers/block/drbd/drbd_protocol.h | 6 ++++-- > > drivers/block/drbd/drbd_receiver.c | 3 ++- > > 3 files changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c > > index 55234a558e98..b824679cfcb2 100644 > > --- a/drivers/block/drbd/drbd_main.c > > +++ b/drivers/block/drbd/drbd_main.c > > @@ -729,7 +729,8 @@ int drbd_send_sync_param(struct drbd_peer_device *peer_device) > > cmd = apv >= 89 ? P_SYNC_PARAM89 : P_SYNC_PARAM; > > /* initialize verify_alg and csums_alg */ > > - memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); > > + BUILD_BUG_ON(sizeof(p->algs) != 2 * SHARED_SECRET_MAX); > > + memset(&p->algs, 0, sizeof(p->algs)); > > if (get_ldev(peer_device->device)) { > > dc = rcu_dereference(peer_device->device->ldev->disk_conf); > > diff --git a/drivers/block/drbd/drbd_protocol.h b/drivers/block/drbd/drbd_protocol.h > > index dea59c92ecc1..a882b65ab5d2 100644 > > --- a/drivers/block/drbd/drbd_protocol.h > > +++ b/drivers/block/drbd/drbd_protocol.h > > @@ -283,8 +283,10 @@ struct p_rs_param_89 { > > struct p_rs_param_95 { > > u32 resync_rate; > > - char verify_alg[SHARED_SECRET_MAX]; > > - char csums_alg[SHARED_SECRET_MAX]; > > + struct_group(algs, > > + char verify_alg[SHARED_SECRET_MAX]; > > + char csums_alg[SHARED_SECRET_MAX]; > > + ); > > u32 c_plan_ahead; > > u32 c_delay_target; > > u32 c_fill_target; > > diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c > > index 1f740e42e457..6df2539e215b 100644 > > --- a/drivers/block/drbd/drbd_receiver.c > > +++ b/drivers/block/drbd/drbd_receiver.c > > @@ -3921,7 +3921,8 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i > > /* initialize verify_alg and csums_alg */ > > p = pi->data; > > - memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); > > + BUILD_BUG_ON(sizeof(p->algs) != 2 * SHARED_SECRET_MAX); > > + memset(&p->algs, 0, sizeof(p->algs)); > > Using struct_group() introduces complexity. Has it been considered not to > modify struct p_rs_param_95 and instead to use two memset() calls instead of > one (one memset() call per member)? I went this direction because using two memset()s (or memcpy()s in other patches) changes the machine code. It's not much of a change, but it seems easier to justify "no binary changes" via the use of struct_group(). If splitting the memset() is preferred, I can totally do that instead. :) -Kees -- Kees Cook