Received: by 10.192.165.148 with SMTP id m20csp4138825imm; Mon, 30 Apr 2018 12:27:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqOP6b7TPSWrtdqWLU9ZdKMX04L1owR+jhqD3g6PDx0+7l6Nde1Khf1erXNVT0q1ZifnIb2 X-Received: by 2002:a63:b344:: with SMTP id x4-v6mr10994208pgt.132.1525116478235; Mon, 30 Apr 2018 12:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525116478; cv=none; d=google.com; s=arc-20160816; b=tFLfqSN2O5Gdjd9GCdX6Kkc7EmGpdfS6LgMHvspudvq+ACjoV/+Zbr0kUHiv3Z0Nw/ fTxpUuaWlCSFW0HTPkGAz+DuTQg+8eWn/g6JwmCmlQMnc5MqwGhQMTPU+eqp5dRj1S4m pFq4RMev8+QoORE33oFSFLw9xYyH3CxpYRkiUV9J9QXYeA6k+RjQn/1yhOvCC5Of5uUx pavU9KbVOPL+l81DK7v4+kQMxrJDvyaY+GsAoz7K5gKcqq28/get94Y+V9a+2Xw5UuwG hoFT3FprVKEExetvGmbDqN6i77pWy9u/TFC104VP+jorhB/Hb2F6d4cBhsrDFZlWDhbc Qekg== 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=QQcnvRTAJkaWQfIY+My41VZQN/JRoPYa+e0s//9DQBw=; b=gLzA9tRo8B7UrYejXAGRQ7+hVlxUNKDkS4/nY6d4eAuDCFko/euRgjcfBrxKwNaR2k qsYR60nOnNUNa1AnBrT16stDFK1gRqSBITRKn98ORF2z1fISGL41+0FNWnBTSn3dS9NJ XNGTSgQfwcs6ElJ5kpZpY/OvxoHf3YFsR3bZ22z7CKLUd421jGcS/I4tBEKxWLa0Qd6o PhmRVtHaigg04IMA35uacMm1yyaR786M1MHY+/PwzR8sbTUFxkivptnm2yxVvZFZnHwk ZrJkQZ3ehrCoWWdlMLQCKnoQRT1bd9haVVA2yvR/m188kJ2bx2ldVU0qom2Q75hyv3Q3 0SzA== 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 b3-v6si2079582plc.14.2018.04.30.12.27.14; Mon, 30 Apr 2018 12:27:58 -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 S1755818AbeD3T0y (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:60634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755290AbeD3T0v (ORCPT ); Mon, 30 Apr 2018 15:26:51 -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 41F3F22E03; Mon, 30 Apr 2018 19:26:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41F3F22E03 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.9 45/61] ARM: amba: Fix race condition with driver_override Date: Mon, 30 Apr 2018 12:24:48 -0700 Message-Id: <20180430183955.176440110@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@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.9-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);