Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1862773rwb; Fri, 19 Aug 2022 10:37:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TkOkM1QetdPDpzJPXXdSz5GJ3YVYQ4vOimFl1/3CBtzhmhaM6XP/sDHsHV9XHQVpdOPMS X-Received: by 2002:a63:e851:0:b0:42a:3bc0:9ad1 with SMTP id a17-20020a63e851000000b0042a3bc09ad1mr3587051pgk.543.1660930660128; Fri, 19 Aug 2022 10:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930660; cv=none; d=google.com; s=arc-20160816; b=bHAYK0anlxwWUvH8B+LFndyZ04SJVM7SFCXN3xkTw5egzkpmj2Q9Y8otMzUZGo+kdD XbF6wyL69bHrqvpB8Q6S/3/nm0dhXYpNOFcSfrA/w74/Y/IR9PZVfrR0uAWb3weN5CHB EAbVweXyGp+soHTdpX0dTsqkGoDiK+6b81TzV4kp7SRVp2mPft7JlmcgPzEULkyA8i+h ICdqU+mu49fypTxieI5l1L5ybvnhlclszAVECsSt1pxtzdr6UCWf0AKzR5J7NXLYMZq1 Ua+hMF4xrse3aQzxeJsqU22zXBBzmE6EcPoBOk5FVqmTE2sPq6N9t/yCkjRm/EzMj+ek WPMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ns1v81coyb4234FcN4EQBGynum6I4Yk/2rsuxQO+0DA=; b=cPK9Tn7dfOIv61F13KZB5c3Sy9QXLnlJg/s5tdXrQjqQ0DtpufE80Thgc4rKZr5oy+ TXZh297KpthCP5Vs8mEZ60XB+fA91HnSKh4bq0IPHvlJJnpAD/j2c4EEXgrL5DmjbrfP /X3UsAU2IvOE2WM8KPzLjSTbcufI16ZIcvobrtbewhzjgi6nqs3CtFI0JH8WZlGIPfdM kS1hRRW4rVb3yYwHgfbsKESuOVjHsM+wl7VR7igG0kW2wIVy8gBLNwy3R6wHYiRClqbd 7mXejA+vGEXSZ8L/NT8EgXDiElSud3yWXKIVCXqf8bxdIH7JkGogPU/TyrHdqR+2NgD0 2ZTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rgu14KGr; 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 k1-20020a170902ce0100b00170d34b95cdsi4458725plg.185.2022.08.19.10.37.28; Fri, 19 Aug 2022 10:37:40 -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=Rgu14KGr; 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 S1353180AbiHSQgp (ORCPT + 99 others); Fri, 19 Aug 2022 12:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353706AbiHSQc0 (ORCPT ); Fri, 19 Aug 2022 12:32:26 -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 A7300104752; Fri, 19 Aug 2022 09:06:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 921336177D; Fri, 19 Aug 2022 16:06:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BECCC433D6; Fri, 19 Aug 2022 16:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925197; bh=NZrKYplqe+G17tIETm+2hY+3VvZ50Kmxurqtsx++LB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rgu14KGru+GV/HNT2EO3nIKu6DZn4hJK/X0d5OstI2QTFHSv4AS9vFR5THEgdoRRF 9rpJbZLp0s3wBXsiZE0j6h3sGj5XOUjuR14GHklyoOSEzI9N7+bEH86bcxqYRqgZeB r8E2h106p5WEUWOThLabMu8O2bXEuoXvuf0PgWS8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthew Wilcox , Heiko Carstens , Alexander Egorenkov , Alexander Gordeev , Sasha Levin Subject: [PATCH 5.10 407/545] s390/zcore: fix race when reading from hardware system area Date: Fri, 19 Aug 2022 17:42:57 +0200 Message-Id: <20220819153847.638702238@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Alexander Gordeev [ Upstream commit 9ffed254d938c9e99eb7761c7f739294c84e0367 ] Memory buffer used for reading out data from hardware system area is not protected against concurrent access. Reported-by: Matthew Wilcox Fixes: 411ed3225733 ("[S390] zfcpdump support.") Acked-by: Heiko Carstens Tested-by: Alexander Egorenkov Link: https://lore.kernel.org/r/e68137f0f9a0d2558f37becc20af18e2939934f6.1658206891.git.agordeev@linux.ibm.com Signed-off-by: Alexander Gordeev Signed-off-by: Sasha Levin --- drivers/s390/char/zcore.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c index 1515fdc3c1ab..3841c0e77df6 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c @@ -48,6 +48,7 @@ static struct dentry *zcore_reipl_file; static struct dentry *zcore_hsa_file; static struct ipl_parameter_block *zcore_ipl_block; +static DEFINE_MUTEX(hsa_buf_mutex); static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE); /* @@ -64,19 +65,24 @@ int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count) if (!hsa_available) return -ENODATA; + mutex_lock(&hsa_buf_mutex); while (count) { if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { TRACE("sclp_sdias_copy() failed\n"); + mutex_unlock(&hsa_buf_mutex); return -EIO; } offset = src % PAGE_SIZE; bytes = min(PAGE_SIZE - offset, count); - if (copy_to_user(dest, hsa_buf + offset, bytes)) + if (copy_to_user(dest, hsa_buf + offset, bytes)) { + mutex_unlock(&hsa_buf_mutex); return -EFAULT; + } src += bytes; dest += bytes; count -= bytes; } + mutex_unlock(&hsa_buf_mutex); return 0; } @@ -94,9 +100,11 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count) if (!hsa_available) return -ENODATA; + mutex_lock(&hsa_buf_mutex); while (count) { if (sclp_sdias_copy(hsa_buf, src / PAGE_SIZE + 2, 1)) { TRACE("sclp_sdias_copy() failed\n"); + mutex_unlock(&hsa_buf_mutex); return -EIO; } offset = src % PAGE_SIZE; @@ -106,6 +114,7 @@ int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count) dest += bytes; count -= bytes; } + mutex_unlock(&hsa_buf_mutex); return 0; } -- 2.35.1