Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1543986rdb; Mon, 2 Oct 2023 12:57:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQysemkb1f4qO0GbRT9jFSUViqgOc7585YC/uQpFHojKR7lOd+BxX/+knYlAs6YfTIyHyB X-Received: by 2002:a05:6358:6f19:b0:13a:6748:9312 with SMTP id r25-20020a0563586f1900b0013a67489312mr10940023rwn.19.1696276657693; Mon, 02 Oct 2023 12:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696276657; cv=none; d=google.com; s=arc-20160816; b=YHUlsODkaeB1FZkYnPq/bqhzwostIdBMBHT0meGS9IfD/8n+X07s97RT1lb6f22qem Ul2R0Ja+eUPvAr7C95R8wlguMdA3MQRgEhEpLHvhQ3KkAFNdwjiGKND6x9F63M+mUNLy cHSCaICNtRoeR5KNAl5SeiPjKK1WSKDn6Nn3Emap3RT1LxG7eq+MlXHUPXXy6/ZjuNXc btMB8kvYq58dhmlldmp5S5fRJ4hz2f0kYCfBMl2ZWUfI1ZpcDny5rJ8w4hqzwHv8onN6 31IWzOozVW02n5bA4YsnJv/zmkUkCMFZLtmGaLhzKMO5BdAcvHw6LqTQmEWVS+72B+z6 RBeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=X22Y+6WPb42oCP5h0wWLFGV3a8KruDFVfrKrZX+kvrI=; fh=pbyDDVPazmpCZjSZlUmUG4EIEuW4PLsa95hv2gmDMcE=; b=tP5pTlqaYo+g434M7y3Ov9peN+nscqwa95gwWWrFraTJIgToQRywQd+ak6+a68Uvww X2Bk/V68FmtXQs2es+9uOMgN29OtE+xtOJbir4tn6k2bif8JoHS8ONpxzUj7b89CNHq7 vlPVASC+0sA5jXofmf9JBZYzuvLhuBN8VN03FpnPi6QudCDGFpnvHFqqhfLw6be2hZyc V9zf2wEzk8VTtn4vo06MSCQpmJxuU8j8j9QemOdWGyN0XCc3tLUsEWqPQSSp5ZJLFa5C H2LJ+T18FsdmOGMwLGiVkhgxe9L7i6K7yDRNtc/UaLaBF9jfs5/f2UxajJzzydBpwwhW cv6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dEDsGfTS; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id z19-20020a056a001d9300b0068a38a9ab84si27521760pfw.176.2023.10.02.12.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 12:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=dEDsGfTS; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 21D55806E3C9; Mon, 2 Oct 2023 04:56:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236828AbjJBLzX (ORCPT + 99 others); Mon, 2 Oct 2023 07:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236814AbjJBLzU (ORCPT ); Mon, 2 Oct 2023 07:55:20 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 881A1D7; Mon, 2 Oct 2023 04:55:16 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2F5271F747; Mon, 2 Oct 2023 11:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696247715; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X22Y+6WPb42oCP5h0wWLFGV3a8KruDFVfrKrZX+kvrI=; b=dEDsGfTSVcjDoo+qxrOtbu33nbW5qJQmgsTJPjhMtMfNpGxNL0hfP+9DWEGtFRiQRJxahb nyq5Tqea/siHVK6Y85k1at3PHoTAWhcz3RZuYI2haOjcSwyURixPo0+ux2Xvk6GeyTHaNj VptL+6/9tXXTxergBbNj1QaqFMRPZoc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696247715; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X22Y+6WPb42oCP5h0wWLFGV3a8KruDFVfrKrZX+kvrI=; b=clkwmVDoOPCbZRayDxKuJ38iOQBoxrLwVfD2SXjfOIn+32hraGDKv+BJmHUzlS4+iD+k6b PMg0fiLujJbTRGCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1671E13434; Mon, 2 Oct 2023 11:55:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id m98eBKOvGmU9FAAAMHmgww (envelope-from ); Mon, 02 Oct 2023 11:55:15 +0000 From: Cyril Hrubis To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org Cc: ltp@lists.linux.it, Cyril Hrubis Subject: [PATCH v3 1/3] sched/rt: Disallow writing invalid values to sched_rt_period_us Date: Mon, 2 Oct 2023 13:55:51 +0200 Message-ID: <20231002115553.3007-2-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002115553.3007-1-chrubis@suse.cz> References: <20231002115553.3007-1-chrubis@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 04:56:02 -0700 (PDT) The validation of the value written to sched_rt_period_us was broken because: - the sysclt_sched_rt_period is declared as unsigned int - parsed by proc_do_intvec() - the range is asserted after the value parsed by proc_do_intvec() Because of this negative values written to the file were written into a unsigned integer that were later on interpreted as large positive integers which did passed the check: if (sysclt_sched_rt_period <= 0) return EINVAL; This commit fixes the parsing by setting explicit range for both perid_us and runtime_us into the sched_rt_sysctls table and processes the values with proc_dointvec_minmax() instead. Alternatively if we wanted to use full range of unsigned int for the period value we would have to split the proc_handler and use proc_douintvec() for it however even the Documentation/scheduller/sched-rt-group.rst describes the range as 1 to INT_MAX. As far as I can tell the only problem this causes is that the sysctl file allows writing negative values which when read back may confuse userspace. There is also a LTP test being submitted for these sysctl files at: http://patchwork.ozlabs.org/project/ltp/patch/20230901144433.2526-1-chrubis@suse.cz/ Signed-off-by: Cyril Hrubis --- kernel/sched/rt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 0597ba0f85ff..aed3d55de2dd 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -37,6 +37,8 @@ static struct ctl_table sched_rt_sysctls[] = { .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = sched_rt_handler, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "sched_rt_runtime_us", @@ -44,6 +46,8 @@ static struct ctl_table sched_rt_sysctls[] = { .maxlen = sizeof(int), .mode = 0644, .proc_handler = sched_rt_handler, + .extra1 = SYSCTL_NEG_ONE, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "sched_rr_timeslice_ms", @@ -2985,9 +2989,6 @@ static int sched_rt_global_constraints(void) #ifdef CONFIG_SYSCTL static int sched_rt_global_validate(void) { - if (sysctl_sched_rt_period <= 0) - return -EINVAL; - if ((sysctl_sched_rt_runtime != RUNTIME_INF) && ((sysctl_sched_rt_runtime > sysctl_sched_rt_period) || ((u64)sysctl_sched_rt_runtime * @@ -3018,7 +3019,7 @@ static int sched_rt_handler(struct ctl_table *table, int write, void *buffer, old_period = sysctl_sched_rt_period; old_runtime = sysctl_sched_rt_runtime; - ret = proc_dointvec(table, write, buffer, lenp, ppos); + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); if (!ret && write) { ret = sched_rt_global_validate(); -- 2.41.0