Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6792114pxv; Fri, 30 Jul 2021 02:26:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj6f3dwBaKRdLkKBp7tMMAii5ZebCJQyFTaXFfp4AbuAoPmM70nSKfbdTO9JtOJiFM4SD6 X-Received: by 2002:a50:85ca:: with SMTP id q10mr1890795edh.3.1627637200346; Fri, 30 Jul 2021 02:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627637200; cv=none; d=google.com; s=arc-20160816; b=QhramzK0Rv0XLOvTnb+cRycxziGiupSxSI/tpOYg9j/n59p/xeCbvs/ywUC2zyDsZ0 leYcDtGnslW231YGYRc/xOHAH16a/RjszsvN5k6xO+4kLu9D1VXfCzEIPUzupaa205j3 ZBJMQUlEDerPn7Qh9cjCFMHv11Jj7CMuZKHOn01NV22gotT0QeTv5Fc0mkw2k8qJKaOr Vd0cvHspu8O1ZYb/gkWOW9Ta3H2QAhYQKqs7chrqnX5TBdTz3Silr522zDTGCNrwaYqJ 43MfF+7Mwqo8Oa8HgDg1B1znOcP5LXunIt40MeqCyxAdsB0j+l/UDXcty2cQ8KMq4H7w x5iw== 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:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=AkuGs7W3jKofUPHLtLFgYg9f4YA+eRGF5if/gTr/VXg=; b=gonazChEhcuW6C1+hDkkEgiD+52AXAVgLgaw8EjRlHa2XDYtXNHNQeirPVp4WgQWbd L7Zh93m89cIOH6nDSm8D8kF//O1JkOSBs+4OVK8bTjdcuhLnYwmNY+0twWiBXXUdcw5I diBTnyhn7NvzBH1hQSDaC1zZgUIgJWhpdZ1rvEEmV1EqxpHNHrqua6n2mAqSmdkPgySI k/dhXFOeF18JYJkM5BS3bcZ+ARxmLwHHQO2x+Y3c+KnbWu5XHeQ3UkYgqILrNnOpYvqj V6YJAz0FK34unsN/04UWBZYM1PgVzOajZEkGaO5lCdy0FRAGf2x92c++vN95hgZSe1h7 XOuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linbit-com.20150623.gappssmtp.com header.s=20150623 header.b=lylUtumR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si1474204ejr.456.2021.07.30.02.26.16; Fri, 30 Jul 2021 02:26:40 -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=@linbit-com.20150623.gappssmtp.com header.s=20150623 header.b=lylUtumR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238207AbhG3J0I (ORCPT + 99 others); Fri, 30 Jul 2021 05:26:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230359AbhG3J0H (ORCPT ); Fri, 30 Jul 2021 05:26:07 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 955FBC0613D5 for ; Fri, 30 Jul 2021 02:26:01 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id r2so10478279wrl.1 for ; Fri, 30 Jul 2021 02:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linbit-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=AkuGs7W3jKofUPHLtLFgYg9f4YA+eRGF5if/gTr/VXg=; b=lylUtumRYNonwKmsPvuJom3wxBHkLf4anhWQaqkh04Z4ai4zZJd08vdZ7peV9SRpsh 8kDAxoMFjhA4/LA7o2la5MrwwsntBQgGjb0I1dUZFTJHnBuxsue7dB41Zed6v8YvFnQx EtWmNPzKWs0OwoVonXjeCSLzamGDsOrch7MlE+WtH/ppN38tQ4p8HLRgifhRRjoPlQkI e7dhso1fixnA6ExwMDoIvam1wge26Ggl97vNBtGlzBzaYUrpPxGPV5UmfIV5g4S/Vge/ 4ukVRSa4etHYaDGK4EAFlKuotQCFXCnz8HEMRP8pLWuHCS1V7/wsG8+TQIpv8pIama72 IoVw== 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 :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=AkuGs7W3jKofUPHLtLFgYg9f4YA+eRGF5if/gTr/VXg=; b=QbyicGvito/nP3Hd0YOwF6OskZl926PkaOcJkPJGA48yxVoHqAewMtCER8Ti8ySIWP CaPr/HKgKfXlMPg3hLmLVfht6Yf2VBJk10gLLbgw9Xh6B0jxCUYTUyhQyB4ceYnhSto+ VhZZ3Stq1WQmz+TWyPEtTi7GE817kk9MQfN6bjAZu1aTioE2AOTCZoncSnRWp0iDgw6J BUOtTs8SOcOkGybdJTOzw6S49g6IpgGBUN/KGI0F/oOfVl9cu+TJKhvbtdVMmjL9IHr4 y4bzkJzIktpWherULzHYwOsCf768PXxs3bYWQI3Byd8PsTzyrmlyE070n0OgsXTCAmzy RSaw== X-Gm-Message-State: AOAM532Z3tYhpFATe8DA3Tz7Dx5G1QEwE/Q2GkaVjkros0g1/UUNM0UK uUSX06N/PYml4y4St3ria0wh1A== X-Received: by 2002:a5d:6448:: with SMTP id d8mr1920645wrw.295.1627637160119; Fri, 30 Jul 2021 02:26:00 -0700 (PDT) Received: from grappa.linbit (62-99-137-214.static.upcbusiness.at. [62.99.137.214]) by smtp.gmail.com with ESMTPSA id v15sm1259298wmj.39.2021.07.30.02.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 02:25:59 -0700 (PDT) Date: Fri, 30 Jul 2021 11:25:57 +0200 From: Lars Ellenberg To: Bart Van Assche Cc: Kees Cook , 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: <20210730092557.GC909654@grappa.linbit> Mail-Followup-To: Bart Van Assche , Kees Cook , 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 References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-49-keescook@chromium.org> <1cc74e5e-8d28-6da4-244e-861eac075ca2@acm.org> <202107291845.1E1528D@keescook> <0d71917d-967f-beaa-d83e-a60fa254627c@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0d71917d-967f-beaa-d83e-a60fa254627c@acm.org> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Thu, Jul 29, 2021 at 07:57:47PM -0700, Bart Van Assche wrote: > On 7/29/21 7:31 PM, Kees Cook wrote: > > 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. > > :) > > I don't have a strong opinion about this. Lars, do you want to comment > on this patch? Fine either way. "no binary changes" sounds good ;-) Thanks, Lars