Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1169881rwd; Tue, 13 Jun 2023 05:58:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6uJc8NTESoCKa53rciD8Gn1lKE96uZKdl9GLK0yNEUIb2VjMYg7Ywv38pRw+uXunyRT3Zu X-Received: by 2002:a17:906:478f:b0:96f:aadb:bf81 with SMTP id cw15-20020a170906478f00b0096faadbbf81mr13625944ejc.45.1686661132239; Tue, 13 Jun 2023 05:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686661132; cv=none; d=google.com; s=arc-20160816; b=Jm7gw3G2UC7q9owOy+ZW+l0f3vXKIDbuI0PWgl10TOQL9nx5PiTO1j6Xd3YISFlI2T epNf6EsQQ2Qy4r9ROsIQCZE2ypbCnu4iXEiOeG9mYmGtpCFRRbFnPOP8jc8MUD0sjBgd BAqECESWVtEOeQVx2WTBoOnqyCZ0Qn30wBLMP2oRlfKP8N13MMyZIP1ZGvdQMxGddcXs 9UGWnes+wxGNJYWoTt/1Vnb2RVkwOB3MQhpjCtoDwkT0y5MnCxPdo8XgJSnK2WweR7P6 bcYD2BpZM/x0GkaWiBOewrf3KeF2tEjY3Lwmup4Km2oKxHkCK0s+0Td1ZJb8PoMiDD3t pD/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QHc7vP5zkhrUmujQoTt/giRPp5gmSgomrWcTeulO5hY=; b=J+S0Cyi6TcVPB+1Aj3TdpS4NoqBdGi81eRf2Clm1Av4Y2DIEEWN0LPs1IArEwiRPo6 SEDT67xrHsvbaTUgnt7ZUBPK5gy/SWMp20X9Kt50twvF02GvIoSWth7aWenSLibReHli L5Eh3Qn6eONzn6aznlI9Z+nOrAaSyQtpRC0iU8mPlujD0fHTDzjsyxUimSoRfZOUNQ0O L13mMU0A/Cv2QFajodJRjxbSe0agDhBhwJnsTmGh4CYsC0q0dngA8i4q+9sDBURAzaZp VE8IicjVt1Op/ayBaODwR1B5xnkqblHCKymKAU51r8HIHn9IN3yTF4lmrMTLoeL8mHxh C1wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A59kENLO; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a1709064d4a00b0094efb4f4271si6877244ejv.434.2023.06.13.05.58.27; Tue, 13 Jun 2023 05:58:52 -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=@redhat.com header.s=mimecast20190719 header.b=A59kENLO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240291AbjFMMlN (ORCPT + 99 others); Tue, 13 Jun 2023 08:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235429AbjFMMlL (ORCPT ); Tue, 13 Jun 2023 08:41:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25B910E9 for ; Tue, 13 Jun 2023 05:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686660025; 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=QHc7vP5zkhrUmujQoTt/giRPp5gmSgomrWcTeulO5hY=; b=A59kENLO/RTqarF1OmD4BDoQHX+rNpW90bCDtaB35C6i0iOIC5wSc9qAj7CA7aoouTKBfg vK6Ze0wmWPdmi92NIyTJ/Y5mpDETlElesdAMIPkrPdiBhbK67c5lJrC9cBcqdYYUx4F9fQ p8D/4kEmDoamcy10QF9F/uYDydPTUxo= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-99RU4DhDOAGqHwPxLXJ64g-1; Tue, 13 Jun 2023 08:40:22 -0400 X-MC-Unique: 99RU4DhDOAGqHwPxLXJ64g-1 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1b3b39e1468so15740515ad.0 for ; Tue, 13 Jun 2023 05:40:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686660022; x=1689252022; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QHc7vP5zkhrUmujQoTt/giRPp5gmSgomrWcTeulO5hY=; b=Fau3Ve7N3yILdI6vKVcUfuXVhcVQw8iU38227mdu9leEwQ0ZkDtCmjZs+0QjcYoN21 1qBI1KeHvccHLJUuE/OCJa4ZKdV1W2daLd1iMk6h5zkonRy5UQh8C3nALr4ZJ6sCriYG LEvGMly0PV2D5E3lfGS0kwCOqf/3G5AWNWRRqopKEq6G5j6tYqY2YDpEuVOSntAsfJyd dSoKuNzcNcorNAYE2f9KrpFOBpCGF7SvcmLFZ+YiMcwPV7iWoGz26fI6Za6oeeK9A+PI jl3/nT0v2l6f1mLiGSnZMdKfbK7TgMjhtrG4hFm4wR4hnrLuqm5u0AylLXflBu/mAYka 5g/A== X-Gm-Message-State: AC+VfDx46vFQ9uSgixMpEcaM8pF80sckYCGLwBMwvNhzKxRITb4oS48w KBV3/YZIt9jyc+futtDGaHwpGb+3CAxaUSkR+6Qq0SQ4rR9qKZAtnRNivgp/2XeW1KKglKlaecg jE4D5QPbQ+iheULiDFM2Flx+xW8iBWHwb6bBY5ugu X-Received: by 2002:a17:902:f691:b0:1b1:93f9:4305 with SMTP id l17-20020a170902f69100b001b193f94305mr10848630plg.60.1686660021770; Tue, 13 Jun 2023 05:40:21 -0700 (PDT) X-Received: by 2002:a17:902:f691:b0:1b1:93f9:4305 with SMTP id l17-20020a170902f69100b001b193f94305mr10848604plg.60.1686660021441; Tue, 13 Jun 2023 05:40:21 -0700 (PDT) MIME-Version: 1.0 References: <20230613030637.2934730-1-islituo@gmail.com> In-Reply-To: <20230613030637.2934730-1-islituo@gmail.com> From: Andreas Gruenbacher Date: Tue, 13 Jun 2023 14:40:08 +0200 Message-ID: Subject: Re: [PATCH] gfs2: Fix possible data races in gfs2_show_options() To: Tuo Li Cc: rpeterso@redhat.com, cluster-devel@redhat.com, linux-kernel@vger.kernel.org, baijiaju1990@outlook.com, BassCheck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 On Tue, Jun 13, 2023 at 5:07=E2=80=AFAM Tuo Li wrote: > Some fields such as gt_logd_secs of the struct gfs2_tune are accessed > without holding the lock gt_spin in gfs2_show_options(): > > val =3D sdp->sd_tune.gt_logd_secs; > if (val !=3D 30) > seq_printf(s, ",commit=3D%d", val); > > And thus can cause data races when gfs2_show_options() and other function= s > such as gfs2_reconfigure() are concurrently executed: > > spin_lock(>->gt_spin); > gt->gt_logd_secs =3D newargs->ar_commit; > > To fix these possible data races, the lock sdp->sd_tune.gt_spin is > acquired before accessing the fields of gfs2_tune and released after thes= e > accesses. > > Reported-by: BassCheck > Signed-off-by: Tuo Li > --- > fs/gfs2/super.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c > index a84bf6444bba..671adf38fe03 100644 > --- a/fs/gfs2/super.c > +++ b/fs/gfs2/super.c > @@ -1059,6 +1059,7 @@ static int gfs2_show_options(struct seq_file *s, st= ruct dentry *root) > } > if (args->ar_discard) > seq_puts(s, ",discard"); > + spin_lock(&sdp->sd_tune.gt_spin); > val =3D sdp->sd_tune.gt_logd_secs; > if (val !=3D 30) > seq_printf(s, ",commit=3D%d", val); > @@ -1070,6 +1071,7 @@ static int gfs2_show_options(struct seq_file *s, st= ruct dentry *root) > val =3D sdp->sd_tune.gt_quota_quantum; > if (val !=3D 60) > seq_printf(s, ",quota_quantum=3D%d", val); > + spin_unlock(&sdp->sd_tune.gt_spin); > if (args->ar_statfs_percent) > seq_printf(s, ",statfs_percent=3D%d", args->ar_statfs_per= cent); > if (args->ar_errors !=3D GFS2_ERRORS_DEFAULT) { > -- > 2.34.1 > Added to for-next (with minor adjustments). Thanks, Andreas