Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4093461imw; Mon, 18 Jul 2022 22:28:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tX1GqNpmhRn/SYiU8/olu9e3+i6A1mSOJTR0fG3bkDeeJOYCSuxX/8Cvk/wJyJVLjEY7BY X-Received: by 2002:a17:902:b7c4:b0:16b:e3d0:c0fe with SMTP id v4-20020a170902b7c400b0016be3d0c0femr31319218plz.98.1658208482075; Mon, 18 Jul 2022 22:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658208482; cv=none; d=google.com; s=arc-20160816; b=k5jnKTXSfL/+h++kn7IdavW3kli/l5Us+2miQVlxTY+P3hrKvO9063skAkxRRXAG58 bcNIHvQPBYl2L9hau6CTa9FG1gOKwqeTw9pFn9hY4Mr0lx8q/aQxDqzvsyp8+JG9HFCK KU36JqjUQY89hwu0UBtsgOieeceZ78RCj452DVqqa152o89DVpsea9OIFCtmW2P4qpcq MDOdJ27iiY2CjiGjr6sGMOLMqXOygK+F+eO62IqVgrOd+GDoVMCrAV8WzdYyGumNJpI2 no06tZVPgJKLcf1k/wT3syXOse/l75cKm5oylgq5SXowHdMPatlTkIzrJKCJb2bgidtG gABg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YFD/RonJhySGGefvyKaAb9AJoup2bE+KD4MJgR4iy2Q=; b=b9cXoy3Kaghj7DAKXJjHRfeHCtSYVB4mHrFrtwX5FuBQ6Zx2zDNEQNDevYdDqBsCLb 3NQG3a7VrgdnFlCq6zTpoS45D94/3A/ed7bXc+cRDe6ETb97xHqlfKT1f+/2DrzTfLGp vPZS1jqnno9sADyQZMH4SOfGYb39Xn3hgPz3xsIf+Ptk0bRCCh2MLz6oyZgtYCIB43fE bVSVfAj0t+PJmpO3wtI5GCdbarPHYXURSnJy15vRp/xzDjrROIx6v6CKOPMdRecL6R2r rTCv6IbUsGnR7IVJNtIid6k4x/+D+Ozq2a3q5u70QbsIEexl6aMkb78rNy+OdQbHd4uL konw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qfeZKaYx; 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=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be26-20020a056a001f1a00b00528d101d6e0si15699595pfb.288.2022.07.18.22.27.48; Mon, 18 Jul 2022 22:28:02 -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=@ibm.com header.s=pp1 header.b=qfeZKaYx; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236243AbiGSF0v (ORCPT + 99 others); Tue, 19 Jul 2022 01:26:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbiGSF0l (ORCPT ); Tue, 19 Jul 2022 01:26:41 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA322494D; Mon, 18 Jul 2022 22:26:41 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J5KYUB032397; Tue, 19 Jul 2022 05:26:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=YFD/RonJhySGGefvyKaAb9AJoup2bE+KD4MJgR4iy2Q=; b=qfeZKaYxAKRQ/K04trbtHbv8OgeNq5lhGsSTfoh+Q6blehEXXomlxVhd9ji8BN5B794r KmR15QejjX+ZgpJWbPmJQXL45PoKOYcLgJs3iFrnJMnqRwZeJjn+bcc7kPBPTPL+Qf2o rZe2DXEtt6XA56oZptkLJb14wb5UGc+2x0y0Ad0PuA1jSG2BqSXOi9RV71vWWJmr0XBj 2luRbOuQ6fhRFfDThzBBvvNwP4gWZCMivlNvuzqrccNJCP3U+D4Bu3aRXtwV2AkHJ61T Tlpg4C4y3dZc+7Cnu1ls0Qa1khu4tocebv/B3bp3X3GJeZ3MnSZ/iRvRW8n7Vv4hlMtZ 6g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdpcq836p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26J5L7wt001287; Tue, 19 Jul 2022 05:26:32 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hdpcq8364-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:32 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26J5L3xd024482; Tue, 19 Jul 2022 05:26:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3hbmy8uh83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 05:26:29 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26J5QQYs18088412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jul 2022 05:26:26 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0E74A4055; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF8D4A4051; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jul 2022 05:26:25 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55669) id 7BEA1E01D7; Tue, 19 Jul 2022 07:16:36 +0200 (CEST) From: Alexander Gordeev To: Matthew Wilcox , Alexander Egorenkov , Heiko Carstens Cc: Baoquan He , Christoph Hellwig , Vasily Gorbik , Al Viro , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v4 1/4] s390/zcore: fix race when reading from hardware system area Date: Tue, 19 Jul 2022 07:16:33 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vHe9p_lO6SoHxjRWlS9rA4IRNet1JtHX X-Proofpoint-ORIG-GUID: Cvqq4MDGPObEKoiht7oW7MZ220olxn5u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190019 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 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.") Signed-off-by: Alexander Gordeev --- 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.34.1