From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752696AbdGHCqK (ORCPT ); Fri, 7 Jul 2017 22:46:10 -0400 Received: from mail-it0-f41.google.com ([209.85.214.41]:35478 "EHLO mail-it0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752637AbdGHCqJ (ORCPT ); Fri, 7 Jul 2017 22:46:09 -0400 MIME-Version: 1.0 In-Reply-To: References: <20170707185729.GA70967@beast> From: Kees Cook Date: Fri, 7 Jul 2017 19:46:07 -0700 X-Google-Sender-Auth: ljAnt3gky5uLenSMEl5os7DDmm4 Message-ID: Subject: Re: [PATCH] exec: Limit arg stack to at most _STK_LIM / 4 * 3 To: Linus Torvalds Cc: Andy Lutomirski , "Eric W. Biederman" , Michal Hocko , Ben Hutchings , Hugh Dickins , Oleg Nesterov , "Jason A. Donenfeld" , Rik van Riel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 7, 2017 at 3:24 PM, Linus Torvalds wrote: > On Fri, Jul 7, 2017 at 11:57 AM, Kees Cook wrote: >> To avoid pathological stack usage or the need to special-case setuid >> execs, just limit all arg stack usage to at most _STK_LIM / 4 * 3 (6MB). > > Ok, this I think I should just apply, but would prefer to avoid > multi-line complex conditionals around things like this. > > So how about the attached slightly edited version instead? > > I didn't test it (and I'm not really committing it until I get an ack > or two), but it seemed all ObviouslyCorrect(tm). FamousLastWords(tm). > > Comments? That works for me, thanks. Testing showed the same sane results: $ ulimit -s 32768 $ ./args Detected max args size near: 6291023 bytes $ ulimit -s 24576 $ ./args Detected max args size near: 6291022 bytes $ ulimit -s 20480 $ ./args Detected max args size near: 5242448 bytes $ ulimit -s 16384 $ ./args Detected max args size near: 4193871 bytes $ ulimit -s 8192 $ ./args Detected max args size near: 2096719 bytes $ ulimit -s 4096 $ ./args Detected max args size near: 1048143 bytes -Kees -- Kees Cook Pixel Security