Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752041AbcDOQRR (ORCPT ); Fri, 15 Apr 2016 12:17:17 -0400 Received: from mailscanner02.zoner.fi ([84.34.166.11]:37590 "EHLO mailscanner02.zoner.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbcDOQRQ (ORCPT ); Fri, 15 Apr 2016 12:17:16 -0400 Date: Fri, 15 Apr 2016 19:17:03 +0300 From: Lasse Collin To: Kees Cook Cc: Ingo Molnar , Baoquan He , Yinghai Lu , Ard Biesheuvel , Matt Redfearn , x86@kernel.org, "H. Peter Anvin" , Ingo Molnar , Borislav Petkov , Vivek Goyal , Andy Lutomirski , Andrew Morton , Dave Young , kernel-hardening@lists.openwall.com, LKML Subject: Re: [PATCH v5 06/21] x86, KASLR: Update description for decompressor worst case size Message-ID: <20160415191703.7a3212de@tukaani.org> In-Reply-To: <1460672954-32567-7-git-send-email-keescook@chromium.org> References: <1460672954-32567-1-git-send-email-keescook@chromium.org> <1460672954-32567-7-git-send-email-keescook@chromium.org> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Antivirus-Scanner: Clean mail though you should still use an Antivirus Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1807 Lines: 42 On 2016-04-14 Kees Cook wrote: > + * Above analysis is for decompressing gzip compressed kernel only. Up to > + * now 6 different decompressor are supported all together. There are six decompressors in Linux now, but the number can change and the comment become outdated, so I suggest omitting the exact number here. > And among them > + * xz stores data in chunks and has maximum chunk of 64K. Hence safety > + * margin should be updated to cover all decompressors so that we don't > + * need to deal with each of them separately. Please check > + * the description in lib/decompressor_xxx.c for specific information. > + * > + * extra_bytes = (uncompressed_size >> 12) + 65536 + 128. lib/decompress_xxx.c, not lib/decompressor_xxx.c. Referring to those files is problematic because only decompress_unxz.c talks about the safety margin. The explanation of the safety margin for gzip is still in misc.c instead of decompress_inflate.c. I suspect that safety margin calculations haven't been made for other compressors in Linux, so there is nothing that people could read for more information. At least such information isn't present in the comments or commit messages. For example (and a bit off-topic), there is a possible sign of too small safety margin in decompress_unlzo.c, where a memcpy call can get overlapping dest and src buffers: /* When the input data is not compressed at all, * lzo1x_decompress_safe will fail, so call memcpy() * instead */ if (unlikely(dst_len == src_len)) memcpy(out_buf, in_buf, src_len); The overlap can only happen if there's enough incompressible data near the end of the kernel image. It still works in practice as long as memcpy works with overlapping buffers for dest < src. -- Lasse Collin | IRC: Larhzu @ IRCnet & Freenode