Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3395774rwa; Tue, 23 Aug 2022 04:11:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6uQzu4ZSChXEbetgxl5rn6AhsM16xftqqJbaBtAVV1zV+5xr05JVw4aMIInismRAH9VCGq X-Received: by 2002:a17:90b:4f81:b0:1fb:23bb:5183 with SMTP id qe1-20020a17090b4f8100b001fb23bb5183mr2809150pjb.140.1661253113148; Tue, 23 Aug 2022 04:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253113; cv=none; d=google.com; s=arc-20160816; b=kky7jy9FAQ4Z+bEF6VhsTCHdq/pkgWHclLkvQZ8d+CcHrUrBcP8/VdP8Rkg6Ud6rqb f23A7uCJOduoynvQ0BsRKRHWAbsTmP18F8zP082YRPUZpViPB3j5YU1ylhkFAojKVgDM gMQ7/PIk7prFdZD2osHq8KlkLVp8O/e5iE8NGrpOTDavOdhqywPWqBzNJiLS7ag7q9nP 11IVgpfisQoOSwCdcn/rkN4HYa322Jlai5Qv+JYCQjoYWZQBa9QPSg7ZBcB1cBJ9/iY4 8F8jcHx0iix7RjRrnUjih7NfU1V79SGbzN9mSeT4mSLrGIQhNIeRc6wcdlmNwPTOOtun zyyw== 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=pTbURup71EIonGiEjUYLG7vqTpId8n6QpZpJCVr9wGk=; b=zPfZkxur82aUnHomWP+wFtSZ6vLPKO5J+NO7FWvvYKn/eBjY1mFVzBpVAGwMIUCPWw GCRUGl2GZwz9dt4ojduD9sG4DvOolSz26reW5Z7wBP8cDXCiMHVFaNUZFpm5nLqV8aIS xy7MGnyHli9rvoyxYwDPO7B3y9t1YW1l7ICU882LjpJQre0rqPI9jj/x8hOH/Gca7won Fg/qL9UWXNFcONdyAARZe2QJKKD7d9Sr/Tq60NdbBQ6Ve4FTwwVtnk2appGmLgaOoYJd S7AUDvY9d3yAhdjB6+YfKLo6p1tJyLr/haD7R0MfP9U7+K3SmFl6lQNLCu6bo5BcUAUp 7RSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z7yyIIiA; 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 i7-20020a655b87000000b0041d00d8df51si14499241pgr.406.2022.08.23.04.11.40; Tue, 23 Aug 2022 04:11:53 -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=Z7yyIIiA; 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 S1356427AbiHWKrW (ORCPT + 99 others); Tue, 23 Aug 2022 06:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356067AbiHWKlZ (ORCPT ); Tue, 23 Aug 2022 06:41:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F121065272; Tue, 23 Aug 2022 02:08:35 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3F7A9B81C53; Tue, 23 Aug 2022 09:08:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87E71C43145; Tue, 23 Aug 2022 09:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245712; bh=kT4S0FkdxQREl8KpWC8Zu8gJ7tAnQVe/AqEwUxUa6v0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7yyIIiAJoJ+HOGOaIBsJ2Zfbei5mb/jikT7mzmpoRlNSRxPn3ajdRRmJ2Do7amxU +4KzqVIBqFX1AGcsNDgimbN9do7kHT7rjG8aGAwgBUrbfUHjajeiZm6fTUIHmlxU5v uFGft0y5GW+RTkrGKG1ShKNXOJybi+5ipLPWPhVY= 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 4.19 165/287] s390/zcore: fix race when reading from hardware system area Date: Tue, 23 Aug 2022 10:25:34 +0200 Message-Id: <20220823080106.292878681@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 76d3c50bf078..ba8fc756264b 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c @@ -53,6 +53,7 @@ static struct dentry *zcore_reipl_file; static struct dentry *zcore_hsa_file; static struct ipl_parameter_block *ipl_block; +static DEFINE_MUTEX(hsa_buf_mutex); static char hsa_buf[PAGE_SIZE] __aligned(PAGE_SIZE); /* @@ -69,19 +70,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; } @@ -99,9 +105,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; @@ -111,6 +119,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