Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4546518pxa; Mon, 10 Aug 2020 11:43:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRdGyouQu1J9axWoK8A7K9IABWYlO5uX2iK99dyOlzjAtsAGdR09SjgWN5POCsEHdH/YvU X-Received: by 2002:a17:906:b89a:: with SMTP id hb26mr8031885ejb.425.1597085027451; Mon, 10 Aug 2020 11:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597085027; cv=none; d=google.com; s=arc-20160816; b=R6NqrTMtOJCscrI2AxNoaIF5YuhVj4eeFAqqM5Vlo8p9QrBhcE5rRG/yIoGdlxJ36m eZNJM7xQbNsBnnDr3aTbtkxOSOwnGOcDDfWruvB8yyXj9jg8gWxsgMy9RxhZpJepIbqk hl77W7paEMEqE9R12pHsaRJKaC+Bcsan1cua7fXVO1FFbP5JVAc958qmi7UF1dcFzB9n 9NMZjgokFaVti04eJkBFwdN/U69fC3LsKqpw4qUUC9H25+IsQdmP8reC3mJEcIlHo5zn T0jkXQWPGRI7i6WRD/7+eKJCsuXY7izhy08UqOHmoeJZj/zcCRwqBY43Ch1vdmmq7RA/ dcHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=2YOnc0kll4m3YxcmbFSRJJkj/GVHFhX1hbh9DgR6W44=; b=T2qCp9u8xf5socnTXNM2XhsX/35cfiKy7P1nbsnlAPllFVQPPgSKlTmXhG8QDzbVnz 7qePGcjGcAzVCQEF7cxhmuLxHYvdZ+8SgJbCyXXrCO+E1xL4rE3Z3R8iX1lh4ouVSv9v MZTwrc48R93mSpSwVRmA1Yvb4RMh4kYqweBjHa+mYgg8pwjAwBDe2ERnkWPTdv2q7Uy2 rodVRaBenihyzFx5tJa/otMCdYgKU/zK2C8GK4GaYp/1DQpSwebraBirO0XyGkm3snHd uelEYCzMYmdOevTd5OlLBNgz/JD/Iof45C6WyppNu4LaExGN4hNBxLph8rJzS16k6Jup 159w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si12381838edn.358.2020.08.10.11.43.24; Mon, 10 Aug 2020 11:43:47 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbgHJSku convert rfc822-to-8bit (ORCPT + 99 others); Mon, 10 Aug 2020 14:40:50 -0400 Received: from lithops.sigma-star.at ([195.201.40.130]:57076 "EHLO lithops.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgHJSku (ORCPT ); Mon, 10 Aug 2020 14:40:50 -0400 Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id CD01161D8ABB; Mon, 10 Aug 2020 20:40:47 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hU8bXeKPAT8V; Mon, 10 Aug 2020 20:40:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 6AAEC61D8ABC; Mon, 10 Aug 2020 20:40:47 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id aOzKDsZ6vDg5; Mon, 10 Aug 2020 20:40:47 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 425DD61D8ABB; Mon, 10 Aug 2020 20:40:47 +0200 (CEST) Date: Mon, 10 Aug 2020 20:40:47 +0200 (CEST) From: Richard Weinberger To: Pavel Machek Cc: Greg Kroah-Hartman , linux-kernel , stable , Miquel Raynal , Vignesh Raghavendra , stable Message-ID: <1475688016.229129.1597084847149.JavaMail.zimbra@nod.at> In-Reply-To: <20200810163851.GB24408@amd> References: <20200810151804.199494191@linuxfoundation.org> <20200810151804.911709325@linuxfoundation.org> <20200810163851.GB24408@amd> Subject: Re: [PATCH 4.19 14/48] mtd: properly check all write ioctls for permissions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF78 (Linux)/8.8.12_GA_3809) Thread-Topic: properly check all write ioctls for permissions Thread-Index: SPuvyTwnFDc3qnA8Gvg/tEw1EZFuYQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Ursprüngliche Mail ----- > Von: "Pavel Machek" >> When doing a "write" ioctl call, properly check that we have permissions >> to do so before copying anything from userspace or anything else so we >> can "fail fast". This includes also covering the MEMWRITE ioctl which >> previously missed checking for this. > >> + /* "safe" commands */ >> + case MEMGETREGIONCOUNT: > > I wonder if MEMSETBADBLOCK, MEMLOCK/MEMUNLOCK, BLKPG, OTPLOCK and > MTDFILEMODE should be in the list of "safe" commands? Sounds like they > can do at least as much damage as average MEMWRITE... Most of the ioctls you listed are not write-exclusive because existing user space applications (such as mtd-utils) issue them on a read-only fd. So, we didn't want to break them. Before we move such an ioctl to the "non-safe" list, common user space needs to be inspected. This includes, android, openwrt, mtd-utils, etc... On the other hand, this is a raw mtd, it is hard to draw the line. For NAND even reading allows an attacker doing harm, she can trigger read-distrurb super efficiently using the read ioctl... So passing an mtdchar fd (no matter whether read or write mode) to untrusted entities is a bad idea. Thanks, //richard