Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp481970ybb; Wed, 1 Apr 2020 04:03:04 -0700 (PDT) X-Google-Smtp-Source: APiQypJWGfjIL+bJQ13ZGMs0N7xgglqAJIaEMLpzy+WtsdTdZENE1mcEB4UZmX19gO0NhG2UZvVl X-Received: by 2002:aca:c28b:: with SMTP id s133mr2433712oif.36.1585738984340; Wed, 01 Apr 2020 04:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585738984; cv=none; d=google.com; s=arc-20160816; b=m3pfVS3RiOcqOxPcGTn5aFNdSjPPi12YXhh4cq0ixIHa5HBg2nhAgliAnHGtz986VL MUdGSQnwqu0xyNXcr7x2o05s9tm5os+IFKqW7aVx0Lu5vUfxlr/mqVATfKggmZI0oIDS VyL6h3O4mNMuwN4qYrZIexjYt6bbofeNurvssL5pShsSUC3uICO9AAgZF0VHYg/7PMWt EJa2j96YgyeO5Kb3L3QaEXYnpD8puuXhRNocLBDVHgzxpwWRJo8H1Qaqpn48JRfGfavB Y6Z9HeiiLc2ciMcSVXE2AXg1gpESqRlQWgd7QRESWmWeFLergClm90vw20Py6z37Kat+ EwqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=8lIBHKWoS36AfJFAjw2TG84mJUVsS2G4kfqSaxNKWpY=; b=OhbywX37St1H72I0Wbzj4GaDz4gMabxD7QFpZa1Um5DHNfiQwnS43wjMGIZaXOQEra C6w+tizDehl+3dfCoHwUS2Csvbg03TlP4+GsqNWQ/4+Nv+sj7jOz55iRl3c5fCVawz3W ElMkbau8sJBf/Tg8d5GXylMDOR5P+lmnwkA6CXUQ61RunrgsT5tQfaFsY/zdPRAaHRxQ jWQGT7cOtl0JsyuzeMNxiqFR+5jstSPWsVZ9wC6IW6OLxTbhcasEn0JNDrSFH5tP0NkT CnmhBdOOjnyTzGUfGZG6n4rVG+qIGK4+c/EoKg4rlJh0sSjlW+1pFyjKMxj7QbreWPhE sUWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si808910oik.72.2020.04.01.04.02.51; Wed, 01 Apr 2020 04:03:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732255AbgDALBv (ORCPT + 99 others); Wed, 1 Apr 2020 07:01:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:59830 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731343AbgDALBu (ORCPT ); Wed, 1 Apr 2020 07:01:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D02A0AD6B; Wed, 1 Apr 2020 11:01:48 +0000 (UTC) Subject: Re: [PATCH 1/3] kernel/sysctl: support setting sysctl parameters from kernel command line To: Luis Chamberlain Cc: Kees Cook , Iurii Zaikin , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org, Ivan Teterevkov , Michal Hocko , David Rientjes , Matthew Wilcox , "Eric W . Biederman" , "Guilherme G . Piccoli" , Alexey Dobriyan , Thomas Gleixner , Greg Kroah-Hartman , Christian Brauner References: <20200330115535.3215-1-vbabka@suse.cz> <20200330115535.3215-2-vbabka@suse.cz> <20200330224422.GX11244@42.do-not-panic.com> From: Vlastimil Babka Message-ID: <287ac6ae-a898-3e68-c7d8-4c1d17a40db9@suse.cz> Date: Wed, 1 Apr 2020 13:01:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200330224422.GX11244@42.do-not-panic.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/31/20 12:44 AM, Luis Chamberlain wrote: >> + } else if (wret != len) { >> + pr_err("Wrote only %ld bytes of %d writing to proc file %s to set sysctl parameter '%s=%s'", >> + wret, len, path, param, val); >> + } >> + >> + err = filp_close(file, NULL); >> + if (err) >> + pr_err("Error %pe closing proc file to set sysctl parameter '%s=%s'", >> + ERR_PTR(err), param, val); >> +out: >> + kfree(path); >> + return 0; >> +} >> + >> +void do_sysctl_args(void) >> +{ >> + char *command_line; >> + struct vfsmount *proc_mnt = NULL; >> + >> + command_line = kstrdup(saved_command_line, GFP_KERNEL); > > can you use kstrndup() ? And then use kfree_const()? Yes, feel free to I don't follow, what am I missing? Do you mean this? size_t len = strlen(saved_command_line); command_line = kstrndup(saved_command_line, len, GFP_KERNEL); What would be the advantage over plain kstrdup()? As for kfree_const(), when would command_line be .rodata? I don't see using kstrndup() resulting in that. > move __kstrncpy() to a generic kstrncpy(). > >> + if (!command_line) >> + panic("%s: Failed to allocate copy of command line\n", __func__); >> + >> + parse_args("Setting sysctl args", command_line, >> + NULL, 0, -1, -1, &proc_mnt, process_sysctl_arg); >> + >> + if (proc_mnt) >> + kern_unmount(proc_mnt); >> + >> + kfree(command_line); >> +} > > Then, can we get this tested as part of lib/test_sysctl.c with its > respective tools/testing/selftests/sysctl/sysctl.sh ? Hmm so I add some sysctl to the test "module" (in fact the 'config' file says it should be build with 'y', which would be needed anyway) and expand the test instructions so that the test kernel boot has to include it on the command line, and then I verify it has been set? Or do you see a better way? Thanks, Vlastimil > Luis >