From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D2D5C2BB85 for ; Wed, 15 Apr 2020 16:44:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E4A1206D5 for ; Wed, 15 Apr 2020 16:44:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EwXM2PRV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1416194AbgDOQoj (ORCPT ); Wed, 15 Apr 2020 12:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1416183AbgDOQof (ORCPT ); Wed, 15 Apr 2020 12:44:35 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60117C061A0E for ; Wed, 15 Apr 2020 09:44:34 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id a22so78051pjk.5 for ; Wed, 15 Apr 2020 09:44:34 -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=pdVhlXTVp5GfPwUXj6VUlKKGPig0Mq5LnblaVWQhsNw=; b=EwXM2PRVYwopCctyukNi1Jy9/hg/z0XO7R6ERA5H8lQeF+oXDnWxXzaBvG4/tpnaJk EUS2ZH0ou2TLvBuWGGsNknwi3M1uPK00CvyRUMX/rprb0NidhH4cb7OvpZxH10W+Osnk G83vC8Ey8RWVcyBCcgTMDej9RphYZAOY/eHB8= 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=pdVhlXTVp5GfPwUXj6VUlKKGPig0Mq5LnblaVWQhsNw=; b=QNI/8lQP0XX/l7AwuQtah2esDDV7Zo0jgrCohPX8suk7ZEaGz/lUhRhIg/LhxJO5cB WDH/UzYBY67eQl84SZHm51xLgNz5k1mZ/5XMJ3FT4z/aKoz3ZWPVmLGiTN2kdTSySxaP rQKYasJjSBc9XINVoRWOQlfvO+2LVjUCbWNAvK5oNuYb2i6qo2hFDXiC0oxr8dWe/D6i o6D+SRL9G1vyKnF+POjZFA/UFf+5CzsyIAzgNoCeGhTwaRVCYmK4KJojwunU/2Xe2QKc DLsAf6ic3QtfmUtE34JRCSOAwInJUmlofz354ZnjBUSoH/aLQuk91+7yqTZ5iKNxNPTz 2skw== X-Gm-Message-State: AGi0PuarnxMdpEQ3oekn9QIDULq0CpD8UbVpixT+vguuApeGhgvEIhfx 0tpgsDROoI4Sdkml5WLkmm08+g== X-Google-Smtp-Source: APiQypJgMZ6xJFMYuPvklbyB28ygbw+op9ku2YKu7rWsqqyQB/c5p+WB+5D1gw/9Ht/E/DrwxvRBRA== X-Received: by 2002:a17:90a:dac2:: with SMTP id g2mr139955pjx.112.1586969073762; Wed, 15 Apr 2020 09:44:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q70sm14494021pfc.206.2020.04.15.09.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 09:44:32 -0700 (PDT) Date: Wed, 15 Apr 2020 09:44:31 -0700 From: Kees Cook To: Scott Branden Cc: Luis Chamberlain , Greg Kroah-Hartman , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org, Shuah Khan , Arnd Bergmann , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Takashi Iwai , linux-kselftest@vger.kernel.org, Andy Gross Subject: Re: [PATCH] test_firmware: remove unnecessary test_fw_mutex in test_dev_config_show_xxx Message-ID: <202004150943.01DF9E85@keescook> References: <20200415002517.4328-1-scott.branden@broadcom.com> <202004142010.C0847F5@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 15, 2020 at 09:28:18AM -0700, Scott Branden wrote: > Hi Kees, > > On 2020-04-14 8:10 p.m., Kees Cook wrote: > > On Tue, Apr 14, 2020 at 05:25:17PM -0700, Scott Branden wrote: > > > Remove unnecessary use of test_fw_mutex in test_dev_config_show_xxx > > > functions that show simple bool, int, and u8. > > I would expect at least a READ_ONCE(), yes? > I don't understand why you need a READ_ONCE when removing a mutex around an > assignment > of a parameter passed into a function being assigned to a local variable. > > Could you please explain your expectations. Oops, yes, you're right. I misread and was thinking this was reading from a global. This looks fine. Reviewed-by: Kees Cook -Kees > > > > > Signed-off-by: Scott Branden > > > --- > > > lib/test_firmware.c | 26 +++----------------------- > > > 1 file changed, 3 insertions(+), 23 deletions(-) > > > > > > diff --git a/lib/test_firmware.c b/lib/test_firmware.c > > > index 0c7fbcf07ac5..9fee2b93a8d1 100644 > > > --- a/lib/test_firmware.c > > > +++ b/lib/test_firmware.c > > > @@ -310,27 +310,13 @@ static int test_dev_config_update_bool(const char *buf, size_t size, > > > return ret; > > > } > > > -static ssize_t > > > -test_dev_config_show_bool(char *buf, > > > - bool config) > > > +static ssize_t test_dev_config_show_bool(char *buf, bool val) > > > { > > > - bool val; > > > - > > > - mutex_lock(&test_fw_mutex); > > > - val = config; > > > - mutex_unlock(&test_fw_mutex); > > > - > > > return snprintf(buf, PAGE_SIZE, "%d\n", val); > > > } > > > -static ssize_t test_dev_config_show_int(char *buf, int cfg) > > > +static ssize_t test_dev_config_show_int(char *buf, int val) > > > { > > > - int val; > > > - > > > - mutex_lock(&test_fw_mutex); > > > - val = cfg; > > > - mutex_unlock(&test_fw_mutex); > > > - > > > return snprintf(buf, PAGE_SIZE, "%d\n", val); > > > } > > > @@ -354,14 +340,8 @@ static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) > > > return size; > > > } > > > -static ssize_t test_dev_config_show_u8(char *buf, u8 cfg) > > > +static ssize_t test_dev_config_show_u8(char *buf, u8 val) > > > { > > > - u8 val; > > > - > > > - mutex_lock(&test_fw_mutex); > > > - val = cfg; > > > - mutex_unlock(&test_fw_mutex); > > > - > > > return snprintf(buf, PAGE_SIZE, "%u\n", val); > > > } > > > -- > > > 2.17.1 > > > > -- Kees Cook