Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3250621rwb; Mon, 15 Aug 2022 22:19:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR7cv3U+wo1qW5dxlh8NLaw/lHJKFpZl+18spj/6ga3lgE0BrBwdKqFvG6myhaPkdtA3GXUx X-Received: by 2002:a63:81c3:0:b0:41e:17df:aed0 with SMTP id t186-20020a6381c3000000b0041e17dfaed0mr16742664pgd.395.1660627139886; Mon, 15 Aug 2022 22:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627139; cv=none; d=google.com; s=arc-20160816; b=B20PaAWjP9G+y/TYc3jPUYXYTeJysX1xD7nueQHXRFb/LsZkA4h11BhqTlONtLUPi+ Mg2hd3Bi7M9WObs5CycmT4s2tqU/rFeKcbFkp4isjJQ/s2AOLqSvWzhn4GY5QPHVPlJo 7zpmnGxFXdN+R/OiGKdiEVJ5U7JSrp3zcM3utndC4VnzaRZz+/us9y0rYstEzseSRd9N hWlE2A5dHV4tCYAiHxjZtIWaPJeF0BKebcosTkKWvZUZDMhdNxgrHFGM4CVsJ4UgTXnS VHd/9pq8m0sJrSuqq+Y1W6xEsBxtS3NHnSn3icXEucYmqh/9gnzioFZQ2RxT7Jf0YPdU uqWA== 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=NdXmGjjjzm4taJ9vthcw6frvvFwayJfTZFv+lzMjgsI=; b=eGlTabLiBA9TUDaGezJfJQ/mpmoqnmoscENQCA7GQ/oIZo7Ak03HC8N4LprD9PftDG CRLf7S2zWTABpDWSPt4tYLbjvsLw4PhjnTPJuBGZJGe1JAmVJplh3kBZbr9HXUh+4Swv C5Ve64+aTYpiTbjfVX68D9yM80Z8MUh3tY2/a+hh6n1w/3Lb+DhqrqbZFqsSJefcfqU0 5CFmf0j9JgncnvlXPmzNuHBYwZg0u4SNNnMzvN1v1bcQN2CFHCzhxclC9hI2Ks0E7Vig NRPwpDk7KCa3SX2lvS5YqC7wnwmYzqTFvg5kaXmLjZ2yDASqHF8TkQK6fzvDNEjdFEZB 9jUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bOC5Bv96; 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 w24-20020a17090a461800b001f27babb6fbsi10931550pjg.56.2022.08.15.22.18.49; Mon, 15 Aug 2022 22:18:59 -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=bOC5Bv96; 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 S232430AbiHPEwY (ORCPT + 99 others); Tue, 16 Aug 2022 00:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbiHPEsj (ORCPT ); Tue, 16 Aug 2022 00:48:39 -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 26DAFB4421; Mon, 15 Aug 2022 13:43:40 -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 7AF0EB80EAD; Mon, 15 Aug 2022 20:43:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EA18C433C1; Mon, 15 Aug 2022 20:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596217; bh=mQCrq2ntPhCcnbK41SusLBAMdtiHg3E1dAxiOPm3NqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOC5Bv961JegYGD8Un605g5kh4Qs7RqwAm2c10IaAmUYBfLIdn6OTeWQTBzcHAPwD aWHcK9KFXL4ZOSxacLBIDQI7UBorfk6mlLsCtVqfLZ7Thgj2jTfCnxhB4lmdAWOUwx y8n45zCFLCA1dkcwIT9CjOoWQJuypeOQpuxariKo= 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.19 0976/1157] s390/zcore: fix race when reading from hardware system area Date: Mon, 15 Aug 2022 20:05:32 +0200 Message-Id: <20220815180518.771965641@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 516783ba950f..92b32ce645b9 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c @@ -50,6 +50,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); /* @@ -66,19 +67,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; } @@ -96,9 +102,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; @@ -108,6 +116,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