From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F4AC433E0 for ; Tue, 9 Jun 2020 17:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 140D12078C for ; Tue, 9 Jun 2020 17:15:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LryZXbKu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbgFIRPC (ORCPT ); Tue, 9 Jun 2020 13:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbgFIRPC (ORCPT ); Tue, 9 Jun 2020 13:15:02 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24B3C05BD1E; Tue, 9 Jun 2020 10:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UpZXoNnaIyWKzV6Z6O45sLy0hwoaGi/+8KOaNyXYIhk=; b=LryZXbKuN2eGOYk2BNZevWXRQ2 Vz1L4QBFGOZ7HACvE4sUMqRernCPHCikllguj+wYJHCu0s5VtY6ngnkJJji5lXq44AdeRsWaq0bN7 QSu9A2rvLFuaYkJwrc4JPCvEUVHFFLvWxKhHPacP1AlaZfNW2nByB6c5JGoPwFsz2tdKaSQRYyXNQ WrQUwBlH0Figka6mizQcT9XJzl8VgUmLkERrj6tSlrgFfn4EucxYuPj/qcL/JWrUM8U4KrNqFEcpz Emt78qXrFbIRmZ+neeEhNevfxV/32D04k3HD9YCVuG4lrNOIo63vJGtd9zCcYFq9YgyupkPoKjPB3 2SEBcJtg==; Received: from 213-225-38-56.nat.highway.a1.net ([213.225.38.56] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jihpy-00083s-FN; Tue, 09 Jun 2020 17:14:58 +0000 From: Christoph Hellwig To: Alexander Viro Cc: Luis Chamberlain , Kees Cook , Iurii Zaikin , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Vegard Nossum Subject: [PATCH 2/2] sysctl: reject gigantic reads/write to sysctl files Date: Tue, 9 Jun 2020 19:08:19 +0200 Message-Id: <20200609170819.52353-3-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200609170819.52353-1-hch@lst.de> References: <20200609170819.52353-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of triggering a WARN_ON deep down in the page allocator just give up early on allocations that are way larger than the usual sysctl values. Fixes: 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler") Reported-by: Vegard Nossum Signed-off-by: Christoph Hellwig --- fs/proc/proc_sysctl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index df2143e05c571e..08c33bd1642dcd 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -564,6 +564,10 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, if (!table->proc_handler) goto out; + /* don't even try if the size is too large */ + if (count > KMALLOC_MAX_SIZE) + return -ENOMEM; + if (write) { kbuf = memdup_user_nul(ubuf, count); if (IS_ERR(kbuf)) { -- 2.26.2