Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2845903yba; Mon, 22 Apr 2019 14:09:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGtx0xiutgT/FIzf66bG910TIkCfmsQYJvahuLWT4dOfe6DYJIkwKfT39ORWTgy+ZkQOxp X-Received: by 2002:a17:902:7c01:: with SMTP id x1mr21793466pll.299.1555967365347; Mon, 22 Apr 2019 14:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967365; cv=none; d=google.com; s=arc-20160816; b=tJ0HXuZ9ZTEFFYV9hdKyxpw7c5OKsfx7WYsqHTjRj7Y1ZQbvEwReOKZMQFQGAZShSb FShoFT/zLaHL5JsHtkFklTA9dRtgqjxvwl5M3keJaE2FzPo50q8cE9p0XSrF5m8HN1Af uZO5sveZ3ImR/UsEij1HF3vu4wWRzB+Pki+QPWvgcBN3u+vOLmM5ts5jsWVlQUq9y2Yc /QPa5JVfGo9Hrx1V2khs5NgIH3hpsGFe4Zh0gXd1Oeut6fM0MEy/RWARCT40f7+a/SNp uUqwN8A1mPtNlT0kkoq63Mg1OMVWzI8aP6OR6s43YpMEsZVvt2QiLIDPUOFW/UnsZFpk dMVw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rMO7SlSyVNyND2gDx5PUQQILT0x4pJI8ng4+M08k0CY=; b=mCQyfurWnNkXtq8Twx7R/sM4UGnJyHesc10u+NOO2dQQPzlE4rXsAwQiBSSQgZlqbt zS8F2q+gs1sRbEtD7Q8MZkAqrxHU+sARAO3SlnsgPu1aBKmTfDTNpaG9pdUWjE9pnqS6 RhUiYmREOuTq9lkeZOogHvkIJ2+I/qj3ELmNyEWwv+t4qsw4RG8dXN/Ba9mCGhtjP60f VfjbgLdM48WH2qymzKNhfXmD9XxnPDuOL411aJqmAU4I3Qs3h9jW9qClyef+vkrmoOZN zS4fdQl8hBPMGW1axjVFksdKnMVRj7ttMPNyMDyWKWnV/dk6O7jAAF/HoN2OBhpr1zG6 0ENg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0JI4vdqv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si13673835pld.6.2019.04.22.14.09.09; Mon, 22 Apr 2019 14:09:25 -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=0JI4vdqv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730221AbfDVTrP (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:49928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729682AbfDVTrN (ORCPT ); Mon, 22 Apr 2019 15:47:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F41321906; Mon, 22 Apr 2019 19:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962432; bh=UiE1/qz1leytIa5uK7KJExFF85Vy3sYKYepZmd343vA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0JI4vdqvv420vlr+KOX4NDyTo6vmDP8AgbEzhU7wVvFU/R1BEiMdMrtjNVJuzMERt MUFEAVpHx75xIx9vvSFYqq5cFYbXskzVbDc7I6zFNbOcZYMXTHmP/n7bADBUNACbAc G1ny7Sw7DEyyxEjFU7E/MN4GObmcp4Mhe/xWhehw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: raymond pang , Jens Axboe , Sasha Levin , linux-ide@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 60/68] libata: fix using DMA buffers on stack Date: Mon, 22 Apr 2019 15:45:08 -0400 Message-Id: <20190422194516.11634-60-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: raymond pang [ Upstream commit dd08a8d9a66de4b54575c294a92630299f7e0fe7 ] When CONFIG_VMAP_STACK=y, __pa() returns incorrect physical address for a stack virtual address. Stack DMA buffers must be avoided. Signed-off-by: raymond pang Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin (Microsoft) --- drivers/ata/libata-zpodd.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c index b3ed8f9953a8..173e6f2dd9af 100644 --- a/drivers/ata/libata-zpodd.c +++ b/drivers/ata/libata-zpodd.c @@ -52,38 +52,52 @@ static int eject_tray(struct ata_device *dev) /* Per the spec, only slot type and drawer type ODD can be supported */ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev) { - char buf[16]; + char *buf; unsigned int ret; - struct rm_feature_desc *desc = (void *)(buf + 8); + struct rm_feature_desc *desc; struct ata_taskfile tf; static const char cdb[] = { GPCMD_GET_CONFIGURATION, 2, /* only 1 feature descriptor requested */ 0, 3, /* 3, removable medium feature */ 0, 0, 0,/* reserved */ - 0, sizeof(buf), + 0, 16, 0, 0, 0, }; + buf = kzalloc(16, GFP_KERNEL); + if (!buf) + return ODD_MECH_TYPE_UNSUPPORTED; + desc = (void *)(buf + 8); + ata_tf_init(dev, &tf); tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; tf.command = ATA_CMD_PACKET; tf.protocol = ATAPI_PROT_PIO; - tf.lbam = sizeof(buf); + tf.lbam = 16; ret = ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, - buf, sizeof(buf), 0); - if (ret) + buf, 16, 0); + if (ret) { + kfree(buf); return ODD_MECH_TYPE_UNSUPPORTED; + } - if (be16_to_cpu(desc->feature_code) != 3) + if (be16_to_cpu(desc->feature_code) != 3) { + kfree(buf); return ODD_MECH_TYPE_UNSUPPORTED; + } - if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1) + if (desc->mech_type == 0 && desc->load == 0 && desc->eject == 1) { + kfree(buf); return ODD_MECH_TYPE_SLOT; - else if (desc->mech_type == 1 && desc->load == 0 && desc->eject == 1) + } else if (desc->mech_type == 1 && desc->load == 0 && + desc->eject == 1) { + kfree(buf); return ODD_MECH_TYPE_DRAWER; - else + } else { + kfree(buf); return ODD_MECH_TYPE_UNSUPPORTED; + } } /* Test if ODD is zero power ready by sense code */ -- 2.19.1