Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp546887pxj; Thu, 20 May 2021 15:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy14rM5MkhkwzXqh3FdcRiW0sacOv0S+zxNHy3S4ZBIKr62E0IswmJjGz82gENsVEG8WqTj X-Received: by 2002:a50:f695:: with SMTP id d21mr7296130edn.67.1621551285582; Thu, 20 May 2021 15:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621551285; cv=none; d=google.com; s=arc-20160816; b=nNMA5goV8UERnllVfUqsDNHEge1X72CkoT1hFGj1H8ynPlkYbxjB6inRGQapOPCnoG YpYPkMFn4PWcnD6WLrGMEwQ5+nDyEWYH7kYnOu4iOKw1xceu+mKKM1TQjmzUnUHw3Qsd m5+YzA0eN66AgLgp+vxeu3TXeeqKLEbPVrSrUvbM0VSfaxnw1PWAgpIGv0MgCrjZTQN5 PEn2q6sNMngHra262Z9VdiswxGs+BNABRMxJjpbwti7qEMvzycZ6K1AwpwKnsTh4egOj RYFnc3LQtBbxQAmkhqcObyAwzZlq5M5xzKkVB0EVfqAiURS4x9rH9i0AESDWSw+7CGOg GUFQ== 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=3BiauvZQVEhpHOKoAaIP25BZtINiwRI8I5m8Y/Nk8PU=; b=jcUKRN8IGShE8feK74/YY0CUhBlldZjwR9LFjUueNDmvmCn6Ik3p8sV/J124yRa1jV NoTDhhRx6uHwiRv3h+gI/c2JZwUIDx42iP1iSLUSwcU8QPOTBPllzqnWWaLoi5RmWmbU WABAMUh+5jhE3Roui01oyQHHqUsYqECq8EKAJRyevOHPccV2ChdL06pSn9T1uSeJhkyh leS0ZWWmIVzuyomYUuJldvXF3rl5AuiZQ/QeATQ93JzoPq0/6dkTUiN/yMXrf98Eosne k1yce7X5ZOy8T/9ji0uQK/6djDmHfZC8VK0U3BA5PxI2uj1Bzc2FPhY1oOzlzMdptdU1 xapg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O0FOxTIz; 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 q2si3161541edw.144.2021.05.20.15.54.22; Thu, 20 May 2021 15:54:45 -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=O0FOxTIz; 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 S239655AbhETLSS (ORCPT + 99 others); Thu, 20 May 2021 07:18:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:57122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234019AbhETK6M (ORCPT ); Thu, 20 May 2021 06:58:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF44C6191D; Thu, 20 May 2021 10:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504941; bh=Bd7ya/Acu3UmQZhaki/yGBV6VqDbjpKrpEA+fXt7tFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0FOxTIzz3Y11e2tbuZis1U48FFRsvAc69gkTi79eXSx41m9tPfKlLsG/meyGioqm GUWaqhB53CTi/C21hSPbzrCQ/Z8JOsfxJEkN0qoUdnH+HsJEjPVQB4JYxE1RybP3KO gHzG9niKUj9S9z/j/BPB1BYF25gBLIy7IwQV3XZQ= 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.9 107/240] mtd: require write permissions for locking and badblock ioctls Date: Thu, 20 May 2021 11:21:39 +0200 Message-Id: <20210520092112.271357965@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 331183548bc5..b43b8edc18ec 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