Received: by 10.192.165.148 with SMTP id m20csp4146507imm; Mon, 30 Apr 2018 12:37:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq8tRXJ/ALyAsV7nvBZaahMp9wF4Qc6FsUfPZZFcJ6TNphANrVTdvHgPSzsOCbcK6InDuWC X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr13384610plt.126.1525117079242; Mon, 30 Apr 2018 12:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117079; cv=none; d=google.com; s=arc-20160816; b=Jni8mnOhGWl0pDd2tqOf8V8m17iLFjrdZFHJEMF3tDLN0U5cljdLaCsQkqJPC9Wj9G zU+qLVQnzzMKQ2K5obpzXJWy1gbC+VdHmGdZVPvoXTk1eU2SnHKK330zmax6L4p8m6oP 6H7EZko63GLLqvPM3qrklwCFt/RzVOeCGF7eSJhXia7pmj9bWnsumF8uzjLEQ3f/FXxr w9HtQkQ6MisKWz2GYS+LldLG4WmEcUJ7c6UVoo1u+oy5BXinAv+fa8UllvuAScqAMZl3 jqklEu0J5SjBMKSQMzmSOkoAcpITQaNCcKEJVfrlZ+i+qMrfuMT0UmGB2Z0BRHmDerSl fDug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=W1iDUXB7NvT9+P9E/QwR6YWwoxwDKJkINc05lyPLBWg=; b=RHdhOjA0nECrgsY2HexYLQQ4EGPsKiIVO7cR8jPvE7p/PDWyGple1yF5rxzP3iTVuQ ZD+0d5vcVmabKzXb7F/8+j0mumbvFX995mszsrgHDIJ+heAnZLdtOUAA1CXHALm8Exk6 88jmoWj+m2LnGz180b65+U2AIJnHZEXsYd0Ctr+Wuey+0k0CxnWTTkX8/El0Rx0pYFsW +n1uwtdE+sM12aFxWNkEtP7RpMw25RnKI02w2Nu7BN3scmX/7YpfYXDUHP7of7fMsf1y Cn0HKuI0COcC/VW9pL9Zx9/rT3UM1qe20YBjwek8BRFyJs//YumQchS3HeHlBJFxh9qj Gdzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11-v6si8214836plt.284.2018.04.30.12.37.45; Mon, 30 Apr 2018 12:37:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756419AbeD3T2p (ORCPT + 99 others); Mon, 30 Apr 2018 15:28:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:36562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756372AbeD3T2i (ORCPT ); Mon, 30 Apr 2018 15:28:38 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6F45622DCB; Mon, 30 Apr 2018 19:28:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F45622DCB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Todd Kjos Subject: [PATCH 4.16 074/113] ARM: amba: Fix race condition with driver_override Date: Mon, 30 Apr 2018 12:24:45 -0700 Message-Id: <20180430184018.331824098@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven commit 6a7228d90d42bcacfe38786756ba62762b91c20a upstream. The driver_override implementation is susceptible to a race condition when different threads are reading vs storing a different driver override. Add locking to avoid this race condition. Cfr. commits 6265539776a0810b ("driver core: platform: fix race condition with driver_override") and 9561475db680f714 ("PCI: Fix race condition with driver_override"). Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'") Signed-off-by: Geert Uytterhoeven Reviewed-by: Todd Kjos Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/amba/bus.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -69,8 +69,12 @@ static ssize_t driver_override_show(stru struct device_attribute *attr, char *buf) { struct amba_device *dev = to_amba_device(_dev); + ssize_t len; - return sprintf(buf, "%s\n", dev->driver_override); + device_lock(_dev); + len = sprintf(buf, "%s\n", dev->driver_override); + device_unlock(_dev); + return len; } static ssize_t driver_override_store(struct device *_dev, @@ -78,7 +82,7 @@ static ssize_t driver_override_store(str const char *buf, size_t count) { struct amba_device *dev = to_amba_device(_dev); - char *driver_override, *old = dev->driver_override, *cp; + char *driver_override, *old, *cp; if (count > PATH_MAX) return -EINVAL; @@ -91,12 +95,15 @@ static ssize_t driver_override_store(str if (cp) *cp = '\0'; + device_lock(_dev); + old = dev->driver_override; if (strlen(driver_override)) { dev->driver_override = driver_override; } else { kfree(driver_override); dev->driver_override = NULL; } + device_unlock(_dev); kfree(old);