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=-4.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 E2D8BC433E4 for ; Wed, 15 Jul 2020 18:26:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D20F420672 for ; Wed, 15 Jul 2020 18:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbgGOS0Z (ORCPT ); Wed, 15 Jul 2020 14:26:25 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:34524 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725907AbgGOS0Y (ORCPT ); Wed, 15 Jul 2020 14:26:24 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jvm6d-0008Fo-UP; Wed, 15 Jul 2020 12:26:11 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jvm6U-0003IZ-Lu; Wed, 15 Jul 2020 12:26:11 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Kees Cook , Andy Lutomirski , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Al Viro , Luis Chamberlain , linux-fsdevel@vger.kernel.org, Tetsuo Handa , linux-security-module@vger.kernel.org, "Serge E. Hallyn" , James Morris , Kentaro Takeda , Casey Schaufler , John Johansen References: <871rle8bw2.fsf@x220.int.ebiederm.org> <87wo365ikj.fsf@x220.int.ebiederm.org> <20200715064220.GG32470@infradead.org> Date: Wed, 15 Jul 2020 13:23:11 -0500 In-Reply-To: <20200715064220.GG32470@infradead.org> (Christoph Hellwig's message of "Wed, 15 Jul 2020 07:42:20 +0100") Message-ID: <87lfjk3aeo.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1jvm6U-0003IZ-Lu;;;mid=<87lfjk3aeo.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18nYA25PFlqmd+QJj8Nw4u9gsb6kkHODq4= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH 7/7] exec: Implement kernel_execve X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Christoph Hellwig writes: >> +static int count_strings_kernel(const char *const *argv) >> +{ >> + int i; >> + >> + if (!argv) >> + return 0; >> + >> + for (i = 0; argv[i]; ++i) { >> + if (i >= MAX_ARG_STRINGS) >> + return -E2BIG; >> + if (fatal_signal_pending(current)) >> + return -ERESTARTNOHAND; >> + cond_resched(); > > I don't think we need a fatal_signal_pending and cond_resched() is > needed in each step given that we don't actually do anything. If we have a MAX_ARG_STRINGS sized argv passed in, that is 2^31 iterations of the loop. A processor at 2Ghz performs roughly 2^31 cycles per second. So this loop has the potential to run for an entire second. That is long enough to need fatal_signal_pending() and cond_resched checks. In practice I don't think we have any argv arrays anywhere near that big passed in from the kernel. However removing the logic that accounts for long running loops is best handled as a separate change so that people will analyze the patch based on that criterian, and so that in the highly unlikely even something goes wrong people have a nice commit to bisect things to. Eric