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=-8.7 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 2FFA7C31E45 for ; Thu, 13 Jun 2019 16:30:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 050822173C for ; Thu, 13 Jun 2019 16:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560443430; bh=/kg/I5Js5v4YUUnY5DY/lGeNXoseSK3uBXbK6hBDt+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QxqGldVvqmLBisD6Kl68J6iEejAflepJ/8OZwhssGSOq1eqjPwq8ikv4ouYKSEjT9 LW6kn0ZOgRq8Xz4FY2lhjDiVi+kiYf7RwNjuUXuTPdG8xUAbNA64kZH0u1LPGvPd3H fH25f0j6xncG3ZoAQb4WeCO2HqlAu+5ipp0WeXMA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392539AbfFMQa2 (ORCPT ); Thu, 13 Jun 2019 12:30:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:52664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730914AbfFMIez (ORCPT ); Thu, 13 Jun 2019 04:34:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 9A00720851; Thu, 13 Jun 2019 08:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560414895; bh=/kg/I5Js5v4YUUnY5DY/lGeNXoseSK3uBXbK6hBDt+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ij2brdx1tjpjEjxr5M3O1WRpFU6Q7mjwdLsnQrTNzsuNR3pAEKfwuRNjw5GT6CXDb JWaJD10vDzZMiVot1livpZFQmKlNXy6oWW2kzViaCckRC+IZUMYdIV9pIWuz1UMPuA EIsRAIh+XGEJZBTssMcm7ygskU71xeRImJBVZ0aU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, 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 Subject: [PATCH 4.14 03/81] sysctl: return -EINVAL if val violates minmax Date: Thu, 13 Jun 2019 10:32:46 +0200 Message-Id: <20190613075649.319169010@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190613075649.074682929@linuxfoundation.org> References: <20190613075649.074682929@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 f13601a616ad..cfc2c0d1369a 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2732,8 +2732,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