Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753565AbcD1VbB (ORCPT ); Thu, 28 Apr 2016 17:31:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47821 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752244AbcD1VbA (ORCPT ); Thu, 28 Apr 2016 17:31:00 -0400 Date: Thu, 28 Apr 2016 14:30:58 -0700 From: Andrew Morton To: Mathias Krause Cc: linux-kernel@vger.kernel.org, Emese Revfy , Pax Team , Al Viro , Mateusz Guzik , Alexey Dobriyan , Cyrill Gorcunov , Jarod Wilson Subject: Re: [PATCH] proc: prevent accessing /proc//environ until it's ready Message-Id: <20160428143058.0c12162dbc11461144cfa57f@linux-foundation.org> In-Reply-To: <1461870258-17970-1-git-send-email-minipli@googlemail.com> References: <1461870258-17970-1-git-send-email-minipli@googlemail.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1145 Lines: 23 On Thu, 28 Apr 2016 21:04:18 +0200 Mathias Krause wrote: > If /proc//environ gets read before the envp[] array is fully set > up in create_{aout,elf,elf_fdpic,flat}_tables(), we might end up trying > to read more bytes than are actually written, as env_start will already > be set but env_end will still be zero, making the range calculation > underflow, allowing to read beyond the end of what has been written. > > Fix this as it is done for /proc//cmdline by testing env_end for > zero. It is, apparently, intentionally set last in create_*_tables(). Also, if this is indeed our design then a) the various create_*_tables() should have comments in there which explain this subtlety to the reader. Or, better, they use a common helper function for this readiness-signaling operation because.. b) we'll need some barriers there to ensure that the environ_read() caller sees the create_*_tables() writes in the correct order. > This bug was found by the PaX size_overflow plugin that detected the > arithmetic underflow of 'this_len = env_end - (env_start + src)' when > env_end is still zero.