Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2483004imm; Thu, 7 Jun 2018 11:20:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJhPCt7rZTKEjPo8GGQ3ZdvSUVA043RC1/ngGfMPdkcIltrbqbWRGMsThD08+meL/DFmxe2 X-Received: by 2002:a17:902:8e87:: with SMTP id bg7-v6mr3094813plb.129.1528395642361; Thu, 07 Jun 2018 11:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528395642; cv=none; d=google.com; s=arc-20160816; b=wvlS+M1YP2jJi3+ta58jov99xCGu1bAUUbhUDApVW9g0WngbEn8ahafbf3ZaFOLnnS SRCX4qw1QBUNrGawwA2ILpIoDuoHLrkcjo0wAoI6ae3aT5k55eWrcrNxF6bjzSH0lCNn ZhCQgxLDcbW/0rpJpu+T+2iDH98GsQ6YmK7jbumcU5acXCteNpC1DQckfG+NZWjRhTW3 vd3s47L+y1XdgqYFsgRlYcmSJ4oUWhco+k8sVC1HknpzfMMKe8XALzHupa4fbsrSndlq N/elM6g9R2MGVBYI7ACjc+Np/NG3nXEMiKVr2RckgF3oqImJHJOacvhg6KmbeQd87lN5 jdEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=+z/85R9uUNHiRqVOjCqIv72aUJPvVUiadHDZ2yZWOEc=; b=okO4tHkCNF0eaq4HtUiFQovgAeTF0hQ5j6iDe5QUkiYtXMURkGaICndeRGUnMQI++L pZ6U5Kp80HrzrL6fuF0xDG0+bB8RtZN3KQ4K9fjfcUPmhWstZrFqK8f6si3Fu2CpvTRs ldzmGyh3GXy9DvYDXOUEoHSroHJFwavU+zL7jMwaW7589UzoJirozdxdVGQHc51huHxE nDRbkoinXHvnjeqAPUBKdPIo8Dcg1avzESDK+wc720oCds0OxpIgDOthFje05S8PUDu9 cOe/sduIxlcZMjZoHHhq5Otw7aT/o1dFS5xtlfwUthzeTjFI63CGUNZTE+bKIsAcibgS bDtA== 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 187-v6si3888538pgi.254.2018.06.07.11.20.28; Thu, 07 Jun 2018 11:20:42 -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 S964870AbeFGPCN (ORCPT + 99 others); Thu, 7 Jun 2018 11:02:13 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41430 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934978AbeFGPCJ (ORCPT ); Thu, 7 Jun 2018 11:02:09 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbG-0005a0-79; Thu, 07 Jun 2018 15:09:14 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbD-0003Fu-13; Thu, 07 Jun 2018 15:09:11 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jan Luebbe" , "Bastian Stender" , "Ulf Hansson" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 362/410] mmc: block: fix updating ext_csd caches on ioctl call In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 Signed-off-by: Ulf Hansson [bwh: Backported to 3.16: - Also add the definition of MMC_EXTRACT_INDEX_FROM_ARG() - Adjust filename, context] Signed-off-by: Ben Hutchings --- --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -67,6 +67,9 @@ MODULE_ALIAS("mmc:block"); #define PACKED_CMD_VER 0x01 #define PACKED_CMD_WR 0x02 +#define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) +#define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8) + static DEFINE_MUTEX(block_mutex); /* @@ -569,6 +572,24 @@ static int mmc_blk_ioctl_cmd(struct bloc } /* + * 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. */