Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp434056pxj; Thu, 20 May 2021 12:48:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfP9J7+VqGIouyLJQ90V8PlCTUU8mrmALOghd+J5kx9nbc7XiwmgCB7nLElEy9Z2xaudK1 X-Received: by 2002:a05:6402:2215:: with SMTP id cq21mr6749799edb.28.1621540087341; Thu, 20 May 2021 12:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621540087; cv=none; d=google.com; s=arc-20160816; b=ncgsgi75r1/3C7YNFxz7TKP9ktA6IL+3yrOxKN0Q4oizAEqotS0O/f6t5LA2B3gbFq 7e0+XjDUqDJUwuCs3XWLo2y/jdCHKZ3KRpxLu6VH2dXtV0NbJcbYh/kiLdOPg3vBKPBA qoCb7B7Qw48Y6A3dZCbJVAbXZ85b/4rb+ifu70nn/D80VKm+bCVDQBvwN6TTUIfStFjs Y/pkJdF6YOpXzHsK+e2XCXTGiXb46fHHd4bWW+X82kqp6vz5uur3/9j+679b0yZV2F+d F6kHKcvf8gidSwqXNm3mm1FoLPOTrAltno/AS/OuWGnIB8UIrdW1gTLviMo1X/IDI51l EimA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rv3mq61bQYHzNR8ikz5zNFH5C7c1F3q1vJRL6F7Ls44=; b=if50HjOxCTp4PTdY6308TqJ6/ZwDvVCyvjMNrW2xO39YCdJGQ5H2NEUgIlZikbUvZK 6VhWplUmcCltKMjKLmRKHJlDdd6XRzBYH8GEPfKDlC6rrOm5cDx3JCp13zf5D1pC0YDn ugHKPiMZBB/sMfXox4zuUHPoH4Zib4KSjG47KHV/E331UYaANXV/GobIABHkRFePFOR9 FD7PfgpxnJRLt8ml8WMGA6eCF7KxlrrmiqXq5HUClqOGknbLDd2vOs2SiQug847KzT9F 81iGRA5OQOY84DpFZ/t/mI4belnpOgM+QOZILa5BZzPQXcyG6oynWv608dPMTIpCJbYi kxuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sytsyv5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn3si4522536ejc.292.2021.05.20.12.47.43; Thu, 20 May 2021 12:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sytsyv5D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237431AbhETKnF (ORCPT + 99 others); Thu, 20 May 2021 06:43:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:55706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235911AbhETK1t (ORCPT ); Thu, 20 May 2021 06:27:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD2A061482; Thu, 20 May 2021 09:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504244; bh=0rLUmTGbGwzYfbMsvhdrmBckQ13VB8dZ5stH21Xc+Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sytsyv5DQmwqR+5Sl+jqhptkfJSULk03jgTAf7vB6JhBsQW99QVb8MUTgzohNGsK1 V/iTue33vNUZ0pennK+RIEyTo3VZLJJDEaqlSMRc5reC6apn1eYd9IYOBbaxosxovk 0cy0K3A5Hn7jm2LbT67W68bdEAXn+NSrpcewJfxI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Walle , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Richard Weinberger , Miquel Raynal , Sasha Levin Subject: [PATCH 4.14 157/323] mtd: require write permissions for locking and badblock ioctls Date: Thu, 20 May 2021 11:20:49 +0200 Message-Id: <20210520092125.482101642@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Walle [ Upstream commit 1e97743fd180981bef5f01402342bb54bf1c6366 ] MEMLOCK, MEMUNLOCK and OTPLOCK modify protection bits. Thus require write permission. Depending on the hardware MEMLOCK might even be write-once, e.g. for SPI-NOR flashes with their WP# tied to GND. OTPLOCK is always write-once. MEMSETBADBLOCK modifies the bad block table. Fixes: f7e6b19bc764 ("mtd: properly check all write ioctls for permissions") Signed-off-by: Michael Walle Reviewed-by: Greg Kroah-Hartman Acked-by: Rafał Miłecki Acked-by: Richard Weinberger Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20210303155735.25887-1-michael@walle.cc Signed-off-by: Sasha Levin --- drivers/mtd/mtdchar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 18dd333f2d40..0a109277b174 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -689,16 +689,12 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) case MEMGETINFO: case MEMREADOOB: case MEMREADOOB64: - case MEMLOCK: - case MEMUNLOCK: case MEMISLOCKED: case MEMGETOOBSEL: case MEMGETBADBLOCK: - case MEMSETBADBLOCK: case OTPSELECT: case OTPGETREGIONCOUNT: case OTPGETREGIONINFO: - case OTPLOCK: case ECCGETLAYOUT: case ECCGETSTATS: case MTDFILEMODE: @@ -709,9 +705,13 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) /* "dangerous" commands */ case MEMERASE: case MEMERASE64: + case MEMLOCK: + case MEMUNLOCK: + case MEMSETBADBLOCK: case MEMWRITEOOB: case MEMWRITEOOB64: case MEMWRITE: + case OTPLOCK: if (!(file->f_mode & FMODE_WRITE)) return -EPERM; break; -- 2.30.2