Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp64181pxj; Thu, 20 May 2021 04:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4dSkv0c38p6SlPofpFq88rKjvbkPXK7Km19z/k9RBps+asHkYGEQaz4X+XjmxwtZp6nhA X-Received: by 2002:a17:906:fcb4:: with SMTP id qw20mr4316407ejb.216.1621510814415; Thu, 20 May 2021 04:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510814; cv=none; d=google.com; s=arc-20160816; b=J8ZG/pW3kZXX7g7RjoJoQc5aBtzF6cttT7rebvj/s/2hnt+Ga+MX/dgshtQ/PUFVrx ZWwXlt8ANP0AaF3Ek3cX9zbX6+zZHg01aYmuARMMhNW/Pl7T32QEmt48Bon8DtA8I8cP VIB12aO7bA93HgPj6KhZ7g5+D9b9Ai8NuUu919dqsE9GMSvQtP17Nq8wXzaZY5ogMma4 jUV00hLx8oQ3mKsxc9JE4q0traTKjyIXFs0CdaNLqj0hyUcv4UvoqdlvaEDjBh9uHLWh 3vnnEoM33xJsx9gZ6ILeRRexM9XSyRv9Vz9kpgoW5r8SJ/UZ2+6y4THzwpE4KtbZpmTI jpSA== 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=KQ/IOH2llFBF43oXGyuoP1yH3oFtAWC6D222eW3uUfs=; b=I9lu2q4S4yHqJxwDFHBeq+ra9GPrCAJxlU6kqJe/LEjeJ4JXRCgjInGvn/wG+6WNY+ UsGjSIIbxPOszTv3J43sIYixX1O1O+zekUWnf1Z+kmlfgw66OOfJgPTQl+wi73zeFzUF aN0j+BE8hJSbcNGWegOipLCtd3quEjVC/lwvgvlBydkxhI0pgbhRVl49+Ke8fx32WVA6 PMZ2Vrdy0Fdh+VFr9GGwVR7j23MyyP2Zb2qhqiBE1sRUnz7Z7YbvDRdtx0cZmGGrz4p9 pe+Sq3N5S8hRg0o7UWQBPIovUS05W4z1PkdrOqTWCJ6jznETLmUlIiLEuBXK1BTMaclp VxZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZY1oZRXG; 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 w15si2129582edr.379.2021.05.20.04.39.51; Thu, 20 May 2021 04:40:14 -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=ZY1oZRXG; 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 S242464AbhETLf3 (ORCPT + 99 others); Thu, 20 May 2021 07:35:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:37934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240667AbhETLPI (ORCPT ); Thu, 20 May 2021 07:15:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4558561D5D; Thu, 20 May 2021 10:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505335; bh=9F7GBg8iv9FcM4Ynvwy/14HuZRJPF7qdIdcjcDKQ/EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZY1oZRXGp3RXVrVXvzcwPXVIILdqezMOFCjYc4FuH27t28bRPozWLPwxdslkB4np4 eml19KgiX2GyL6NGFPqHvHhBkgPPppyrGtoM2h7ubxtc7Oe+9Fa9STIWIHnM3Jt6tL LkYdx5CSu4BFfUFyWAcWTSplt2SsN7OQR4PruqXQ= 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.4 089/190] mtd: require write permissions for locking and badblock ioctls Date: Thu, 20 May 2021 11:22:33 +0200 Message-Id: <20210520092105.143669910@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 ce87d9506f6a..0a2832782807 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -616,16 +616,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: @@ -636,9 +632,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