Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2631853rdh; Wed, 27 Sep 2023 08:13:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtfOCxSJnvHs2SKnAkkbR74bDbv5GfB97CN34I5s0RFEEsde66lPPG7oNvYKVCT6guaI44 X-Received: by 2002:a05:6a21:7189:b0:15e:a8:6bb4 with SMTP id wq9-20020a056a21718900b0015e00a86bb4mr2153317pzb.8.1695827591560; Wed, 27 Sep 2023 08:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695827591; cv=none; d=google.com; s=arc-20160816; b=tCG9AFAjYrbrD41KFhH9ssJsxtMWQv20S+CXI6YMkoiiXeMoTtQwSA3D53SwyW5AJV cTTaZLYcKPmAJwRxBbY9R00zbhoHfR0G0EPLQnEyaZVdDxvEtzkQbtuCP47VDFyNXMOc COqyKqqa/RAVEIpFP8DnZvdRlPaOo7RQ9AdpypaxhHYgSSnEnsUSRwVkUvUup+bXQuBx 2XCfeT8yoZLO7pCr+cvcTL6U7Wy6Rw4Q+PeXIDGaiG+BTOWBr9xn57bBGKWF2bolKzSa dZV39Pw4OspiluzjtjC/eh2S/yTS/wGB0lu4hXaAJWGdY5myVMvkwn7o0v0cPGzMiwm9 ONbA== 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=rILEJldM2LNAh5PDlpOs8yE1kQbx3ikfUj2Tt3R6aGPvhNlcYK5IWwM2txwRTPQ7EW EoyFM0EkLd9MTHWU6ONXVekNizK5UhkgmG21uKtPvKOyzNPW+X52EsVxZNA7tb7Oxgkt 1f+eq6kYkdjhfhyfSRJlg47XZ05Oi5GH0uraXa/TvaxXRc2AnpFr4l2+7o0lx3sWr4aO v9YcQDefcuYeMV6rfqNGnpnakrXoK6459FibtDu+6FAQuUZHX87kXfOln9tvI1VFI8qN SSMVUNcwxe+x0XtjZ+PwUGEpJ9dBbzgUPrhz79Pm0t9njGolthGudO5xmdfNyPL0p8Py ByGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=pOhGDyaz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=bagf7WGf; 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 k2-20020aa788c2000000b0068a65b26fc6si17377668pff.43.2023.09.27.08.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:13:11 -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=pOhGDyaz; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=bagf7WGf; 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 F2C4281A2369; Wed, 27 Sep 2023 03:30:12 -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 S230057AbjI0K3j (ORCPT + 99 others); Wed, 27 Sep 2023 06:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjI0K3e (ORCPT ); Wed, 27 Sep 2023 06:29:34 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7753194; Wed, 27 Sep 2023 03:29:33 -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-out1.suse.de (Postfix) with ESMTPS id 7918621901; Wed, 27 Sep 2023 10:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1695810572; 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=pOhGDyazFC3Sluv1udrVw/S0G76MABFbcS1RtuJwpjRc7Wm3sePJt5H+LZ1m+pqHFt8UxG ao2RLubFI5p5eEFjZCVyqnfGpgQv0VQafCWVlSdarjTQM3zEvYNi2cJ3j8Xkn6fOa3qGIX T24bHj+2a3q5xCc/ZwASvDLkg+sCIlE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1695810572; 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=bagf7WGfeBW1NaGhmlge+Xnu9MEcC6DWE+gBymZFa2HA4PyFtGavVtOuLU2N7V1lRXyVbF nsVjCi8dgSSZp9Bg== 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 6325A13479; Wed, 27 Sep 2023 10:29:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id JSrYFgwEFGWoMwAAMHmgww (envelope-from ); Wed, 27 Sep 2023 10:29:32 +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 v2 1/2] sched/rt: Disallow writing invalid values to sched_rt_period_us Date: Wed, 27 Sep 2023 12:30:11 +0200 Message-ID: <20230927103012.9587-2-chrubis@suse.cz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230927103012.9587-1-chrubis@suse.cz> References: <20230927103012.9587-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]); Wed, 27 Sep 2023 03:30:13 -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