Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp672282img; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLOOpGP1a0qs++W5QVJWNppgv38ERXVK7p3W401/gA0BSu6F5zBoV/WUu33aBBA4oirDQN X-Received: by 2002:a63:b902:: with SMTP id z2mr9156654pge.428.1553260743371; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553260743; cv=none; d=google.com; s=arc-20160816; b=0c4O/TZrR53u4062K9CnwuZeWEfL7hhDKY0vLnVQAFfFaYkvLy6YUDHi7Q1rhsP7BW 5c2m7jqLaVmhEQUaCH6HTMGkRIBEeDStVROas4U5l7znJeaK/+HbIM+xxEACOZKjJ2f+ FP4e7IAqGgjVNwd7goyodSi4sq8ouzldsCNpk5oKYIWzickCM06TcPQhdd89+P9TdeGT Obymw7PeufjzQnya2oxVA/MlFe4FHb0ZYQEjkC/GVFt/RuTrwQvnrXiqtY9bwI88DYQl 2xMrSPPevUrMilQidxklUvDC2+9Urpgrg0sciR1yo3RSpkHMBrGX6lsG+Ct05MjYAyDY k+VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y8HJ1a1m4LwdhvVqMomSsu1YytJARjZVi9KIbATAiWk=; b=LvXj8jRxasy3no5TIqoprdNzHdc8uNPKuZosAePEGXHgrqlrmNQz4pZO8wv3q3ptCO qwAK2lMPULL8LNfQ25oZPu043WXkJSPgjYXZ2bYJCPJSJEKr7rnVymEZIAFKpJC9KWuG KkzwfsqJr+S0dqxQfwtqvw9UDp9AyQgr8Tejyl7wiLaBUfmN5n4xDg4ZdRLQqtLl0cAU Jtu2HTEAUbcx50HWJoCVZ/dkL7562AMKe/dy6CgNXMOIFbfJ79BHjl45H1AjCsYI1Eg6 AZkmlbYIKkLpAyl45bXG19N6yqxVl55ohR7IUNK/TvYFmwBKlJuGN6sci8vNhGojBABC GPCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jT4QAmJU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si6957142plt.120.2019.03.22.06.18.45; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jT4QAmJU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729301AbfCVLZd (ORCPT + 99 others); Fri, 22 Mar 2019 07:25:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:52904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729290AbfCVLZb (ORCPT ); Fri, 22 Mar 2019 07:25:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 638B120657; Fri, 22 Mar 2019 11:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253930; bh=hYpOdPjGUmDeh0vwJDPNgkS1I5zR9ewbYgJL7d6p3FE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jT4QAmJUJj8vulbbXkV+SdyJGw3NquwL5gvvG5yh6e7P5NX/ghSF9+shaLvaI60hT udn70NV0r/RnPgQPxj2FvCMGX+5AkXbuQUjbkTDmDT+IRflerO6K2FmqzTRCUf1Oux 9IKEs9EH1XkbFaoNPVVeiempkL3TZkPm9JMDQ55s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Stefan Haberland , Martin Schwidefsky , Sasha Levin Subject: [PATCH 3.18 098/134] s390/dasd: fix using offset into zero size array error Date: Fri, 22 Mar 2019 12:15:11 +0100 Message-Id: <20190322111217.254608183@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 4a8ef6999bce998fa5813023a9a6b56eea329dba ] Dan Carpenter reported the following: The patch 52898025cf7d: "[S390] dasd: security and PSF update patch for EMC CKD ioctl" from Mar 8, 2010, leads to the following static checker warning: drivers/s390/block/dasd_eckd.c:4486 dasd_symm_io() error: using offset into zero size array 'psf_data[]' drivers/s390/block/dasd_eckd.c 4458 /* Copy parms from caller */ 4459 rc = -EFAULT; 4460 if (copy_from_user(&usrparm, argp, sizeof(usrparm))) ^^^^^^^ The user can specify any "usrparm.psf_data_len". They choose zero by mistake. 4461 goto out; 4462 if (is_compat_task()) { 4463 /* Make sure pointers are sane even on 31 bit. */ 4464 rc = -EINVAL; 4465 if ((usrparm.psf_data >> 32) != 0) 4466 goto out; 4467 if ((usrparm.rssd_result >> 32) != 0) 4468 goto out; 4469 usrparm.psf_data &= 0x7fffffffULL; 4470 usrparm.rssd_result &= 0x7fffffffULL; 4471 } 4472 /* alloc I/O data area */ 4473 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); 4474 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); 4475 if (!psf_data || !rssd_result) { kzalloc() returns a ZERO_SIZE_PTR (0x16). 4476 rc = -ENOMEM; 4477 goto out_free; 4478 } 4479 4480 /* get syscall header from user space */ 4481 rc = -EFAULT; 4482 if (copy_from_user(psf_data, 4483 (void __user *)(unsigned long) usrparm.psf_data, 4484 usrparm.psf_data_len)) That all works great. 4485 goto out_free; 4486 psf0 = psf_data[0]; 4487 psf1 = psf_data[1]; But now we're assuming that "->psf_data_len" was at least 2 bytes. Fix this by checking the user specified length psf_data_len. Fixes: 52898025cf7d ("[S390] dasd: security and PSF update patch for EMC CKD ioctl") Reported-by: Dan Carpenter Signed-off-by: Stefan Haberland Signed-off-by: Martin Schwidefsky Signed-off-by: Sasha Levin --- drivers/s390/block/dasd_eckd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index ff1ab6da8cff..4bbcdf991c26 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -3990,6 +3990,14 @@ static int dasd_symm_io(struct dasd_device *device, void __user *argp) usrparm.psf_data &= 0x7fffffffULL; usrparm.rssd_result &= 0x7fffffffULL; } + /* at least 2 bytes are accessed and should be allocated */ + if (usrparm.psf_data_len < 2) { + DBF_DEV_EVENT(DBF_WARNING, device, + "Symmetrix ioctl invalid data length %d", + usrparm.psf_data_len); + rc = -EINVAL; + goto out; + } /* alloc I/O data area */ psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); -- 2.19.1