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.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,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 51DD1C28CC1 for ; Sat, 1 Jun 2019 13:25:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BEBD27396 for ; Sat, 1 Jun 2019 13:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559395513; bh=Vn5bjbLClz3xZJlMgYYX06Me+3iLkR/24u4kt7vlo1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qdKj4CGRD75C5YLRwXqEYDzkNO/Bmle7LYuF9/gVZ87VjpEgPHG63DtB7hVfkxe7d tks7k3zTBGWB9rKap1ESULLWBcgTDTznleyTOOLua4lJkLcNpAnJroRVMzYzvQeCWg 7acdBrE4VlTQnXIVwjBePLAaaD6pD+ADZKPzxKms= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729412AbfFANZH (ORCPT ); Sat, 1 Jun 2019 09:25:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:55320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729371AbfFANZH (ORCPT ); Sat, 1 Jun 2019 09:25:07 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2DC2C27375; Sat, 1 Jun 2019 13:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559395506; bh=Vn5bjbLClz3xZJlMgYYX06Me+3iLkR/24u4kt7vlo1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cdBDL5aMEddVHOXEDpkrt5+pjJbrxuOO/dWBSuoPesALwBv7YeEZoK3jfFO3LhtI5 LHPDz9/9sVdyptQSNUyz75JRnjbEBdthLcnug2olrwpKQaGFIo0R3wngpqvn4YBOAL YIfLxtNdQms0QrUmv67rd6iyfpoqGej/2uJ55kd4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christian Brauner , Luis Chamberlain , Kees Cook , Alexey Dobriyan , Al Viro , Dominik Brodowski , "Eric W. Biederman" , Joe Lawrence , Waiman Long , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 03/74] sysctl: return -EINVAL if val violates minmax Date: Sat, 1 Jun 2019 09:23:50 -0400 Message-Id: <20190601132501.27021-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190601132501.27021-1-sashal@kernel.org> References: <20190601132501.27021-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Christian Brauner [ Upstream commit e260ad01f0aa9e96b5386d5cd7184afd949dc457 ] Currently when userspace gives us a values that overflow e.g. file-max and other callers of __do_proc_doulongvec_minmax() we simply ignore the new value and leave the current value untouched. This can be problematic as it gives the illusion that the limit has indeed be bumped when in fact it failed. This commit makes sure to return EINVAL when an overflow is detected. Please note that this is a userspace facing change. Link: http://lkml.kernel.org/r/20190210203943.8227-4-christian@brauner.io Signed-off-by: Christian Brauner Acked-by: Luis Chamberlain Cc: Kees Cook Cc: Alexey Dobriyan Cc: Al Viro Cc: Dominik Brodowski Cc: "Eric W. Biederman" Cc: Joe Lawrence Cc: Waiman Long Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/sysctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index cf0aeaae567e8..6af1ac551ea3a 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2527,8 +2527,10 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int if (neg) continue; val = convmul * val / convdiv; - if ((min && val < *min) || (max && val > *max)) - continue; + if ((min && val < *min) || (max && val > *max)) { + err = -EINVAL; + break; + } *i = val; } else { val = convdiv * (*i) / convmul; -- 2.20.1