Received: by 10.192.165.148 with SMTP id m20csp4193236imm; Mon, 30 Apr 2018 13:34:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqE9jq5d1JAI5FDg2xOraTCKth+WXZnU/al9IKJidRLzpBqnJl48oaqwvNIzMGsBGvVrTcc X-Received: by 2002:a17:902:3c5:: with SMTP id d63-v6mr13541366pld.163.1525120488718; Mon, 30 Apr 2018 13:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120488; cv=none; d=google.com; s=arc-20160816; b=jwMmsELPa4LR8LfqmgAiQzruLobe4QjWU8oqalX9rPslCZxCBpB+UcB+UczdGdFDeK +eMIfQhr71yicR2RaVI4u7ODCOB93cVpopE1PFnj+rJr7L27Uwu8P+OShr2B9KBLE5+t 63IUdAt0pw4aRUUlzvlHcnCttvrcn9Jzel4k2s6sOlhB34a4O4Z+yPBGXF7kFisdTAgH 7SAfeoLHZ2vyfcbCnlAUEsjY+yJN4eGpNw5Kiyo8Z//TUTXk/9JHp/HV6tymtqkTI6MH Z/dtZxZawbC42poPJs1Suh92zM1hk7khEGshJ1zEj+P1AIogvdePOyzju/7suBgPYnOC XaBA== 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=83NSl0JFzZdCbw/whskBZIGi3t4s9VfIwR7NKJkdyH4=; b=L2oSKduLzvQO8Ao8mLCRdJS28lQD8tsvqp5HCB2cdZGxsYc7IEoNzgiSvQSF3gxkLY 0g9OoPL2aF9gOsfzFj20JqWkkAPxGOtseDiFfJEqAty07WhH0Kku5gNYYwnS7IuwXVgx Ld/BogYNHPu15eYNkz1CJorawdVGBPCf0dgPpWDHEkCC9vbIHGR8n0zxNZaO/SxnvSy2 /2VhFMnT4bGvjUWHdeRX73qkDsLXlE8mgarreCIfD/MC5MZZ83y9qWHoBVmM/+lUWZKS GFtQn/jypn6xZ1F7rRZ+QQB2fvE4RrafkIE6V+hKpXgygpTMA7Yt7mCNZ6sjp2jdwTCI pdFQ== 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 bg6-v6si6398404plb.243.2018.04.30.13.34.34; Mon, 30 Apr 2018 13:34:48 -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 S1755868AbeD3UdD (ORCPT + 99 others); Mon, 30 Apr 2018 16:33:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:59250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755463AbeD3T0D (ORCPT ); Mon, 30 Apr 2018 15:26:03 -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 5FF7F22DC2; Mon, 30 Apr 2018 19:26:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FF7F22DC2 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.4 36/44] ARM: amba: Fix race condition with driver_override Date: Mon, 30 Apr 2018 12:24:47 -0700 Message-Id: <20180430190947.776165866@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@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.4-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 @@ -68,8 +68,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, @@ -77,7 +81,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; @@ -90,12 +94,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);