Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4597768pxj; Wed, 12 May 2021 08:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFrsWUG0COpZnbvzw1XzBUJnlzplYObkT4b3DU88k+I6r4YrN0JVPoZCQZIKg0jU5RQz4F X-Received: by 2002:a05:6402:254a:: with SMTP id l10mr44705839edb.145.1620835098143; Wed, 12 May 2021 08:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835098; cv=none; d=google.com; s=arc-20160816; b=bfqRVysKn3VVw2jLaIr3lUF4mZOayn6Q+zXkre+0MbOde2Nt6ZMbw43F+5K1P7cPPs MFulqfeEwxDplISjbrSP5d5E/yvePPAFNaJC83GFfp2/f2em75hntTpMxZVIzANY070t 68LXvRHHbprOLNfuPAwxpqu4pPmYLu6nd4UzZzR726aPGIaxqEgD4fNSWOIl+Ph3mHnx 3h0ch8KpHCc9OaIK2wxoR943N0NUCrCmYm2x1UpFIpRlYy4cIBh84ACo1b/JnMrfCAPy wucNzYLJkpDyfkm2Lno+fHMay0yzRFAAe11DqDXgHxkmNchn30eAooyFYS7C+7AQXlda 7MrQ== 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=BaUuJYaEqz4X9xLDhXI2AyJZFpCR75br46LZIyHAEIk=; b=g5oMZkVsQkCtJXTfsjl3yzT0DoB6G9WfZ/FrQkUHmJIaaMNiRvM0Sv2TRZiQs0qtOd Hs2nLK5vRVAma5i0c6yZ1S4KooicCQbp+tEXF/MvWUa36V4Dk6bNzcIItvmPXfab2PZ0 KNc6RiwTMh76jacjY69twK92S890cIwg/208O1tHcujx5Fn9vSY6oCp2OjQ6B/MqtCxt zw801EwtnsVPFt3T3lkyoLFX8Ot00Y5yWILkyalaJ4VmMBVB0gt3yJKzONWYLsRlEfy9 naz4MuJOTw2M4JDzBHCEw2ui2Wyitu4hvzQol0IstJS2uLEKwHhqmhT7ho+8RgTECGYO IUPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VQ9HKIpN; 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 c16si10100edy.463.2021.05.12.08.57.50; Wed, 12 May 2021 08:58:18 -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=VQ9HKIpN; 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 S236688AbhELPz0 (ORCPT + 99 others); Wed, 12 May 2021 11:55:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:40848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235080AbhELP0m (ORCPT ); Wed, 12 May 2021 11:26:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF6F760FE9; Wed, 12 May 2021 15:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832293; bh=SYshFkon4dkzsHtIlKC4cOrzk4l4Libof4t9guq9SQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VQ9HKIpNSjmPQrYLBkUmjV5nZMzRzmgvgY/1J7oKFO0I6tu0NFcrBMKKVBtMBMtzP XNixzx9frluFWNljLrr1pH7ZPdn2vbi/avNWVdRM7HCThH/gYYVCE6XMgvXi3e27XY +gw4il4v8I8QvFMIIVvNfUKwSxXHLeKgy/D6fUX4= 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 5.10 185/530] mtd: require write permissions for locking and badblock ioctls Date: Wed, 12 May 2021 16:44:55 +0200 Message-Id: <20210512144825.920101194@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 b40f46a43fc6..69fb5dafa9ad 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -651,16 +651,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: @@ -671,9 +667,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