From patchwork Fri Oct 16 02:50:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11840793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B881214B4 for ; Fri, 16 Oct 2020 02:50:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DA74208C7 for ; Fri, 16 Oct 2020 02:50:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="k4Av33K4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DA74208C7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 61B58940076; Thu, 15 Oct 2020 22:50:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C96394006D; Thu, 15 Oct 2020 22:50:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B91F940076; Thu, 15 Oct 2020 22:50:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 1CC9594006D for ; Thu, 15 Oct 2020 22:50:06 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AA58982499A8 for ; Fri, 16 Oct 2020 02:50:05 +0000 (UTC) X-FDA: 77376259170.07.bulb57_5712cf027219 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 870C71803F9AA for ; Fri, 16 Oct 2020 02:50:05 +0000 (UTC) X-Spam-Summary: 1,0,0,f245a1e43deeef0e,d41d8cd98f00b204,akpm@linux-foundation.org,,RULES_HIT:41:355:379:800:960:967:973:988:989:1260:1345:1359:1381:1431:1437:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2525:2559:2563:2682:2685:2731:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6261:6653:7576:9025:9545:10004:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12986:13069:13161:13229:13311:13357:14181:14384:14721:21080:21324:21451:21627:21939:21990:30054,0,RBL:198.145.29.99:@linux-foundation.org:.lbl8.mailshell.net-64.100.201.201 62.2.0.100;04y8aqet1c9aqb3faa3dixehfa795ypjs3goa615n9e1kkz4uttscoby1fsygw5.hnam9zem9od9gkshnucgsto7biha4ng5rstq6hpfjqey9iyzp1q6mk7p839g51u.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:2 6,LUA_SU X-HE-Tag: bulb57_5712cf027219 X-Filterd-Recvd-Size: 2788 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 16 Oct 2020 02:50:05 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F19C8208C7; Fri, 16 Oct 2020 02:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602816604; bh=XcQvWTejN+lCBG0TETX9FiiE6U9N+R/DWeORU8x1ASU=; h=Date:From:To:Subject:In-Reply-To:From; b=k4Av33K4cXgqBbRdDoc4oE79nDIekwmzp0uSbCZEVyr/NDYBLecFUUYpr5UABzrI4 pb85gNQ9iP+TgUs6TBHNqPscQxilmZj960oOLD5DOUFmPMbWMMs8IZcO/HMCrClJo7 fZyrov9W27UAXHGR4Axb/9NNO75Z90fasgbEAlpw= Date: Thu, 15 Oct 2020 19:50:03 -0700 From: Andrew Morton To: akpm@linux-foundation.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, raven@themaw.net, torvalds@linux-foundation.org, willy@infradead.org Subject: [patch 144/156] autofs: harden ioctl table Message-ID: <20201016025003.otAbjz8xU%akpm@linux-foundation.org> In-Reply-To: <20201015192732.f448da14e9854c7cb7299956@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Matthew Wilcox Subject: autofs: harden ioctl table The table of ioctl functions should be marked const in order to put them in read-only memory, and we should use array_index_nospec() to avoid speculation disclosing the contents of kernel memory to userspace. Link: https://lkml.kernel.org/r/20200818122203.GO17456@casper.infradead.org Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Ian Kent Signed-off-by: Andrew Morton --- fs/autofs/dev-ioctl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/fs/autofs/dev-ioctl.c~harden-autofs-ioctl-table +++ a/fs/autofs/dev-ioctl.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "autofs_i.h" @@ -563,7 +564,7 @@ out: static ioctl_fn lookup_dev_ioctl(unsigned int cmd) { - static ioctl_fn _ioctls[] = { + static const ioctl_fn _ioctls[] = { autofs_dev_ioctl_version, autofs_dev_ioctl_protover, autofs_dev_ioctl_protosubver, @@ -581,7 +582,10 @@ static ioctl_fn lookup_dev_ioctl(unsigne }; unsigned int idx = cmd_idx(cmd); - return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx]; + if (idx >= ARRAY_SIZE(_ioctls)) + return NULL; + idx = array_index_nospec(idx, ARRAY_SIZE(_ioctls)); + return _ioctls[idx]; } /* ioctl dispatcher */