Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp455656ybz; Tue, 21 Apr 2020 12:20:08 -0700 (PDT) X-Google-Smtp-Source: APiQypLGzBAGXISfVBNhwTjVk585QkX0t3gFzdOlm1PHHTuL0lLSq8zTGxZlDmmG0etR5OJbUi2n X-Received: by 2002:a17:906:f208:: with SMTP id gt8mr23347848ejb.124.1587496807976; Tue, 21 Apr 2020 12:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587496807; cv=none; d=google.com; s=arc-20160816; b=rdA2wsXY+Hi1vAeElY7md68J+7ZPYC0JhVl7FDjxqTqYhUynnNph2Ml0cFGxG9yyqS aatu4HCj/ql8jOllWoLMoxszlIHVBIC8ciILueLgfY+SWNjOi0IntrE9BM96g88j3VVf KPi3BqdQrgjwtmosHeNKjRhkSC6hHcAHyzmixC2j8VGHQu53JVL5w59V3XXtlMZaIaHa csA9J8Qb01reWs3VRM2KsgADmmgiY9TakzVwBtpye8q2KCRJsTkn4NsILlhlm2Na1msE zeC94FhG0h//HeEkoq2yDYfqwRUj5ls9KsQaj/pKLs9Ckk/kfNfIkb+iJiAogo6kkfr0 N1pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=k6gT4freNSamQthz5Jei2Sbv3JMOWpOSlij/M07nr20=; b=fUlZbaWPUxz+gTLXF9X7ckDH5J3yfmcEoBIHiGneR9DPGPPyUyJULZTvlNNPt4JaK+ IGDz555352+WlDaDIM1lGVP2/UeaSlZ81dEkOSTeNWybYn6P655xOksdL2EUKteoajCk yTwRF8fnlKTLENBJmrECL8G80s26uuu0i3lwAWJ26Er7YiPh+bB9sxI4OiDnvvdY1F1B y0Ktz3O6y8LKokU04Q7O9xyJsFwj2/p8HO4P1DJb79/VDC0iY6vtEmexf8zUNsV6Xlu3 AZZo0atOg6Qk8ZhTPckoO3xzin72Up9vBVg5d/mWXkYtZhIsxdYH0O2IYc0O2nv4/5rR Dt5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si2181302ejr.170.2020.04.21.12.19.44; Tue, 21 Apr 2020 12:20:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726039AbgDUTQZ (ORCPT + 99 others); Tue, 21 Apr 2020 15:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725902AbgDUTQY (ORCPT ); Tue, 21 Apr 2020 15:16:24 -0400 X-Greylist: delayed 1579 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 21 Apr 2020 12:16:24 PDT Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C516AC0610D5; Tue, 21 Apr 2020 12:16:24 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQyNT-007mDc-HD; Tue, 21 Apr 2020 19:16:15 +0000 Date: Tue, 21 Apr 2020 20:16:15 +0100 From: Al Viro To: Christoph Hellwig Cc: Kees Cook , Iurii Zaikin , Alexei Starovoitov , Daniel Borkmann , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH 5/5] sysctl: pass kernel pointers to ->proc_handler Message-ID: <20200421191615.GE23230@ZenIV.linux.org.uk> References: <20200421171539.288622-1-hch@lst.de> <20200421171539.288622-6-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200421171539.288622-6-hch@lst.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 21, 2020 at 07:15:39PM +0200, Christoph Hellwig wrote: > Instead of having all the sysctl handlers deal with user pointers, which > is rather hairy in terms of the BPF interaction, copy the input to and > from userspace in common code. This also means that the strings are > always NUL-terminated by the common code, making the API a little bit > safer. > > As most handler just pass through the data to one of the common handlers > a lot of the changes are mechnical. > @@ -564,27 +564,38 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf, > if (!table->proc_handler) > goto out; > > - error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, buf, &count, > - ppos, &new_buf); > + if (write) { > + kbuf = memdup_user_nul(ubuf, count); > + if (IS_ERR(kbuf)) { > + error = PTR_ERR(kbuf); > + goto out; > + } > + } else { > + error = -ENOMEM; > + kbuf = kzalloc(count, GFP_KERNEL); Better allocate count + 1 bytes here, that way a lot of insanity in the instances can be simply converted to snprintf(). Yes, I know it'll bring the Church Of Avoiding The Abomination Of Sprintf out of the woodwork, but...