Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26182195rwd; Mon, 3 Jul 2023 06:32:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlFKuw35O/PLtGd/icFvCE9fN+JqZ65iAgK9jigO7NGVFQ1bGk35ZH4Q4Wa6To1uNPO9FqbL X-Received: by 2002:a05:6a00:1402:b0:681:6169:e403 with SMTP id l2-20020a056a00140200b006816169e403mr7475698pfu.8.1688391135652; Mon, 03 Jul 2023 06:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688391135; cv=none; d=google.com; s=arc-20160816; b=fe4Lu7ooxn9RfAi/+V4uv+I0gKdfSEdPRzZULQipVk/zgaARC0evtqB5KuKeqFaKfR flcDOwa1eIb1mdcGqydwIa0CjWNivECVotUwekT4FY18Dpp4pXYuVIHXWOsZSpvAyHma OBdveAyRdQECpzfdT1a2HdbBa1UHoo9Un/D9vlmCOkMhUXYAXy77N+HNXVizGO8CfGmS oUphBGhKeJtX0rxP813grsVgvg/K5jLzDbZEzAJGzmAzjTsxCLj65jfOcb7+SaMxtczq OAws1p1G/XMPG1MG29zqMbB5aV+RRVBB26+VbOU00CjpGo4QcO+cTuah88noXZTWbi9h CAmw== 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=mQq6iKf/eTU7Bi1/LgY1p74qdcpMO0l1TGCYp1cKO4Y=; fh=Ynqp+VEGs3E9yiacqFSbnPMUEKFdloMcaMZa1WOf0mU=; b=C19IWjgYh4L1TA4kcDb7tNB0pD8UC7Z+s0t7OCgNocba9/GShxj8SW/FXlVn8E/m5+ c212xCHxbXSjD4K+Ub/7YTHkb+cSHH0XTmK4UV+BeHgM6b1NeMvw7dBQRMAtJmFrBNcB v9Z7HjfRRMJYXH3s5QMtA2cVQYIOu3n7TjcxZluR/GUcBhzw/M1QgcTHI5wVTJ8p/+uR VdrLNoHcSokbrEBx5wIR3aMk7CWPZDL369Uz4PV8feKxG6k5nH/L+E9T9jnMUgLk+ACo EbBvWCt4zRkeVRzkXjddQAzcRxt1cryVmW5SBXM07KLdFYyYe1Bd1m2NJe0dyfdLStcm ZHEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I8F8HmNd; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25-20020a630d59000000b00553a56f7b34si18781724pgn.788.2023.07.03.06.32.02; Mon, 03 Jul 2023 06:32:15 -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=@linuxfoundation.org header.s=korg header.b=I8F8HmNd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbjGCNYQ (ORCPT + 99 others); Mon, 3 Jul 2023 09:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbjGCNYO (ORCPT ); Mon, 3 Jul 2023 09:24:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69986E64 for ; Mon, 3 Jul 2023 06:24:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F3A7360DCF for ; Mon, 3 Jul 2023 13:24:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39712C433C9; Mon, 3 Jul 2023 13:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1688390649; bh=VZy2IJH5Zp0zLi0PzjAHnGOCdKj0aY+Y8o+P9lCkN1o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I8F8HmNdG9BW6Pn4dfstQ/++oGyIpGpnFDwBv6EyIJeOEdyYDkgIV5YWLJfCW0+tC o6mCKWnNKCf2IN6T7HZx9RGCl7mo5S7T9t2qvOoBcXxXlYC5buXgKjENv8PgmitGG9 4npV7+PBamAUU6t68b1Z1l6Ci2FxPDe5d2TyfGDI= Date: Mon, 3 Jul 2023 15:23:53 +0200 From: Greg KH To: Tuo Li Cc: dtwlin@gmail.com, johan@kernel.org, elder@kernel.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, baijiaju1990@outlook.com, BassCheck Subject: Re: [PATCH] staging: greybus: fix a possible data-inconsistency due to data race in get_serial_info() Message-ID: <2023070352-upscale-bankable-76a7@gregkh> References: <20230626084339.998784-1-islituo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230626084339.998784-1-islituo@gmail.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 Mon, Jun 26, 2023 at 04:43:39PM +0800, Tuo Li wrote: > The variables gb_tty->port.close_delay and gb_tty->port.closing_wait are > ofter accessed together while holding the lock gb_tty->port.mutex. Here is > an example in set_serial_info(): > > mutex_lock(&gb_tty->port.mutex); > ... > gb_tty->port.close_delay = close_delay; > gb_tty->port.closing_wait = closing_wait; > ... > mutex_unlock(&gb_tty->port.mutex); > > However, they are accessed without holding the lock gb_tty->port.mutex when > are accessed in get_serial_info(): > > ss->close_delay = jiffies_to_msecs(gb_tty->port.close_delay) / 10; > ss->closing_wait = > gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? > ASYNC_CLOSING_WAIT_NONE : > jiffies_to_msecs(gb_tty->port.closing_wait) / 10; > > In my opinion, this may be a harmful race, because ss->close_delay can be > inconsistent with ss->closing_wait if gb_tty->port.close_delay and > gb_tty->port.closing_wait are updated by another thread after the > assignment to ss->close_delay. And how can that happen? Also you have trailing whitespace in your changelog text :( > Besides, the select operator may return wrong value if > gb_tty->port.closing_wait is updated right after the condition is > calculated. > > To fix this possible data-inconsistency caused by data race, a lock and > unlock pair is added when accessing different fields of gb_tty->port. > > Reported-by: BassCheck As per the documentation for research tools like this, you need to explain how this was tested. thanks, greg k-h