Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3414116rwa; Tue, 23 Aug 2022 04:30:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JH+XvLqjSxzMsyi04hQ3ERh6NbfaQRLZE5Aiiikxb+ShxKoAAk2LiQmKfNwt8MkmGenDq X-Received: by 2002:a05:6402:4311:b0:447:9fb:b710 with SMTP id m17-20020a056402431100b0044709fbb710mr3178440edc.272.1661254220554; Tue, 23 Aug 2022 04:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254220; cv=none; d=google.com; s=arc-20160816; b=MjaRmerkihuFZvYxF8LHJrNROIW1jHXlVvRYsotC4g2ubh9raxopK3R5b+RotGhY6s 9KyTVshlrTnoH9JP59ah882WESHSFNItf74OtrEZrQm88RSuQo7Nqx7nhlxdn30vNlYY QfwNjRdtJKMRXe0JThhl2pfe4Gbt65jTgUe/NcmZEO+XXtOjtdAyZ9zWLHjOXHRw8u7q PvuCw5+m1sf1sAuae836pYO8/S/Ir32CyV4wEoW738noAn6ws4oRWPIiVui7q6t4Sb01 IAW8kDQHhslFT4zSJrGYNORkRAB0GtL26R+fQTq04jom1SOTfWB86/teCUo/5wNOBsO8 NjMg== 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=neQ1Cy9zmK1wWTShL3dlWjDYpfmKgyqv0cp6WfA/ihw=; b=ytjDpZAcqVxeaVx0zzKcgpAe8+gAZVmPfsuPp7znM+oQ4YuFl0Kpi2g/ZkGalsh7vq 71IBupaopI/5+sgwIpyxWDGd11O53Ahj7cu9+GiNvOzOK1LPPGuWNu7ah9If6Fbp+L3a +wYKxP7xUxbXdpN5Sn3l82jPpf2Y29gO6Ja2wxbZ0ssFf2+X/uT3FllPeX7sVAXBhljL P9hhAYdwQNEDD03FOHNX1TSMx50tIq/2FpPa7nm+SfR7QVcw8iL7GSM8LJnBC+YUdjiy C4N/ijJiDTdD/0tWucNybok+JXVia4l9HTDAcHFpPeP6uUYLpoBwz0CpjNvafKdokdAK pyVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="lEq/DUBl"; 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 z23-20020a50cd17000000b0043d373fd120si2051191edi.47.2022.08.23.04.29.55; Tue, 23 Aug 2022 04:30:20 -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="lEq/DUBl"; 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 S1346797AbiHWJ7G (ORCPT + 99 others); Tue, 23 Aug 2022 05:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346985AbiHWJzh (ORCPT ); Tue, 23 Aug 2022 05:55:37 -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 505689FAB6; Tue, 23 Aug 2022 01:46:50 -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 18BA161485; Tue, 23 Aug 2022 08:46:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21ADFC433D6; Tue, 23 Aug 2022 08:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244408; bh=hKuHHiLafn/QwQz1nmKb0m+Sc2+ysGzFRZNdqguwTrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEq/DUBlLJs/KwS4ScFSMuWmSgWf8lZyUfDcKVcBmcVbvJiRb4vl5W2qpct0F57hq /mrPyDUjBxwOjrlLyw2s3r6FMBVMEy+WVk96AOCQdMHHJjWX9hkV55TKgqxU6/Rrmh 0eP+pJb+kqQcE5donPW1feJcKUioVip6KwEul09Y= 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.14 133/229] s390/zcore: fix race when reading from hardware system area Date: Tue, 23 Aug 2022 10:24:54 +0200 Message-Id: <20220823080058.454139478@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 aaed778f67c4..9748ef463233 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