Received: by 10.213.65.68 with SMTP id h4csp891957imn; Tue, 27 Mar 2018 10:41:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jsQ/4w8tstAuq2DrpW9ehUN4q74ZsSB8O/dN5ATlZC/rVZYvdhKY7KBlQvZFEJNlHNbrt X-Received: by 10.99.149.86 with SMTP id t22mr181233pgn.144.1522172494117; Tue, 27 Mar 2018 10:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522172494; cv=none; d=google.com; s=arc-20160816; b=Ak1blBs6YcBsHDI99wjJUoSFxSBqnn4qAZ2BY24vXyXE1UPsXAwak4L7UZIJBv1cbC HVkdufHPBaf3b9NFdtVIs7/VsN0lyQUEhJhdspQIK8jnGEn/7zsYZ6knyCJy0dcj/jOz 9hUieRHeNWJOmDS7M49RSsGFMMSEgXOG0uoU3ozDh8Z7IgZ1RzdAFadmvZWaTHim92BK dDGptqcoCyDFTuEZEU5TjYcI2iJPxi8lkSgj6LbDYJv61i+YwzVGEyAvHcI3Eo8H8r3e AhVWvcMPyjjppITlRWy3ZWUNWuiS30xoKO9fjj2RJlQABMzU5363SliCvwH5Sv+cdUxb j0YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GSlMdcIKzFihNBKRorcgLy7KUZhTF3ZOwKMJwFEmwho=; b=UQMiBB5SgyD+53ZzMwC268Ab5YxfN6bb8VyjgQmNANAXVl6P0iHyE+b1CPcJdDsTSo yr6BbTroPXfZS8JBjElirbKQ+zx3yfZ8iSGZMzvQeDHEtVjLRvP48CCFGQrGMDO5q3fQ Att6xI6WqCDkRPn57QnNl4M6Jjh9s3OvNGx+KZSzSyA50aFlk0RqPW4ni2qE2rMjltEf qJCeuPGQb9kagySN519IkI93vWM4mzsJQy/oOrl/bgGp/sUNmWXXJLCawIqi1xhoxb3d 81q8BwFEj4uz3LZDghIyF0FhP/xAfVPCdt5VGgRH7oflt8WD5lI66SOUBabAgEamGLGv 4Qvg== ARC-Authentication-Results: i=1; mx.google.com; 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 91-v6si1651500pld.396.2018.03.27.10.41.19; Tue, 27 Mar 2018 10:41:34 -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; 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 S1753040AbeC0RkR (ORCPT + 99 others); Tue, 27 Mar 2018 13:40:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44248 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754152AbeC0QeO (ORCPT ); Tue, 27 Mar 2018 12:34:14 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A2F6B1210; Tue, 27 Mar 2018 16:34:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bastian Stender , Jan Luebbe , Ulf Hansson Subject: [PATCH 4.14 018/101] mmc: block: fix updating ext_csd caches on ioctl call Date: Tue, 27 Mar 2018 18:26:50 +0200 Message-Id: <20180327162751.085101518@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bastian Stender commit e74ef2194b41ba5e511fab29fe5ff00e72d2f42a upstream. PARTITION_CONFIG is cached in mmc_card->ext_csd.part_config and the currently active partition in mmc_blk_data->part_curr. These caches do not always reflect changes if the ioctl call modifies the PARTITION_CONFIG registers, e.g. by changing BOOT_PARTITION_ENABLE. Write the PARTITION_CONFIG value extracted from the ioctl call to the cache and update the currently active partition accordingly. This ensures that the user space cannot change the values behind the kernel's back. The next call to mmc_blk_part_switch() will operate on the data set by the ioctl and reflect the changes appropriately. Signed-off-by: Bastian Stender Signed-off-by: Jan Luebbe Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/block.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -65,6 +65,7 @@ MODULE_ALIAS("mmc:block"); #define MMC_BLK_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ #define MMC_SANITIZE_REQ_TIMEOUT 240000 #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) +#define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8) #define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \ (rq_data_dir(req) == WRITE)) @@ -539,6 +540,24 @@ static int __mmc_blk_ioctl_cmd(struct mm } /* + * Make sure the cache of the PARTITION_CONFIG register and + * PARTITION_ACCESS bits is updated in case the ioctl ext_csd write + * changed it successfully. + */ + if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_PART_CONFIG) && + (cmd.opcode == MMC_SWITCH)) { + struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev); + u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg); + + /* + * Update cache so the next mmc_blk_part_switch call operates + * on up-to-date data. + */ + card->ext_csd.part_config = value; + main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK; + } + + /* * According to the SD specs, some commands require a delay after * issuing the command. */