From patchwork Mon May 4 19:08:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11527461 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 66B4A81 for ; Mon, 4 May 2020 19:09:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2A3D42073B for ; Mon, 4 May 2020 19:09:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IEU5IwMx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A3D42073B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EAA38E0077; Mon, 4 May 2020 15:08:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 59BA78E0058; Mon, 4 May 2020 15:08:59 -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 4B03E8E0077; Mon, 4 May 2020 15:08:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 34EF28E0058 for ; Mon, 4 May 2020 15:08:59 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id F2EE616910 for ; Mon, 4 May 2020 19:08:58 +0000 (UTC) X-FDA: 76779973956.23.rice62_314a9290f9d0a X-Spam-Summary: 2,0,0,6a59e5c92fc3ce4a,d41d8cd98f00b204,keescook@chromium.org,,RULES_HIT:41:355:379:800:960:966:973:988:989:1260:1277:1312:1313:1314:1345:1437:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3874:4321:4385:5007:6261:6653:8603:10004:10400:11026:11232:11658:11914:12296:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:13439:13895:14096:14097:14181:14394:14721:21080:21444:21627:30051:30054,0,RBL:209.85.210.193:@chromium.org:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:25,LUA_SUMMARY:none X-HE-Tag: rice62_314a9290f9d0a X-Filterd-Recvd-Size: 3698 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 19:08:58 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id d184so6014492pfd.4 for ; Mon, 04 May 2020 12:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=Zrx3KcYEt5bVqdNCWLI716yOCASV0eftVoL6kM8jlEE=; b=IEU5IwMxFtRk3KIEubc7CSarG2e5aA3KYJVCBlu5RFT6cG8AIhTu/rNtCCVcZhY5Mc 6psUHFRL28vexVfV1Tp5r/wPpyt9Hv9eV4SW3rmUcmmF0Nj+SDXwV9JJpUl8SbDeFl4s X+OaxkcLd2hZyiZtGCIkCm8VLdQE1QArMAS8g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Zrx3KcYEt5bVqdNCWLI716yOCASV0eftVoL6kM8jlEE=; b=lYoQY22nF9jodPQDosQJ6Ni+wRT5+jXJTas1eMPdn2afB3SQB3uWXhj/iDRHe3asdG qjWoutlxhEO1VJxeq2NzVeLYrmrr0khD22t8vvcZ/21US35TPOD39UdoJJt7Oseg1Hob 3MIPrvUomY0PRskfKOiRg96Kj9BLHXHkHZrInG8WnjKGyybK8OXPZxoLKimVZO3FNhRh Au2jEndj05/LWbWvxAhwfPklQ/X1Zw0UCthcO2urpc3hKgRr71KNXphhTQps61AL5Upk JNpFUq4A0VSENGQdOhJLQIG+KEunLwItCeiFvMqwrUi3ihaE9dMxQlsQUrNaPlRj2Fwq t+1g== X-Gm-Message-State: AGi0PuaIOjTcPtjjdzG6nAE5Nrl5+Ermmj0eA/4xQGkvj5iGuED6Ele5 kiAVNctu+uN0G6yAHaq6+1Nr+w== X-Google-Smtp-Source: APiQypK4ozjl+LdphG8sRjiK+3521UTvXFxbtTSfBtQdVv4J5SnSauPrkUIQ1A1bSi3nL/QSZDKBJA== X-Received: by 2002:a63:df0a:: with SMTP id u10mr410764pgg.79.1588619337719; Mon, 04 May 2020 12:08:57 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d18sm9498013pfq.177.2020.05.04.12.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 12:08:56 -0700 (PDT) Date: Mon, 4 May 2020 12:08:55 -0700 From: Kees Cook To: Christoph Hellwig Cc: Luis Chamberlain , Iurii Zaikin , Alexey Dobriyan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] sysctl: Make sure proc handlers can't expose heap memory Message-ID: <202005041205.C7AF4AF@keescook> MIME-Version: 1.0 Content-Disposition: inline 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: Just as a precaution, make sure that proc handlers don't accidentally grow "count" beyond the allocated kbuf size. Signed-off-by: Kees Cook Acked-by: Christoph Hellwig --- This applies to hch's sysctl cleanup tree... --- fs/proc/proc_sysctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 15030784566c..535ab26473af 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -546,6 +546,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, struct inode *inode = file_inode(filp); struct ctl_table_header *head = grab_header(inode); struct ctl_table *table = PROC_I(inode)->sysctl_entry; + size_t count_max = count; void *kbuf; ssize_t error; @@ -590,6 +591,8 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, if (!write) { error = -EFAULT; + if (WARN_ON(count > count_max)) + count = count_max; if (copy_to_user(ubuf, kbuf, count)) goto out_free_buf; }