Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752314AbdDCVas (ORCPT ); Mon, 3 Apr 2017 17:30:48 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34494 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751580AbdDCVao (ORCPT ); Mon, 3 Apr 2017 17:30:44 -0400 Date: Mon, 3 Apr 2017 14:30:41 -0700 From: Eric Biggers To: David Howells Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: Re: [PATCH] KEYS: fix dereferencing NULL payload with nonzero length Message-ID: <20170403213041.GA140817@gmail.com> References: <20170403175929.GB72831@gmail.com> <20170401213428.17097-1-ebiggers3@gmail.com> <3451.1491234402@warthog.procyon.org.uk> <6884.1491247244@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6884.1491247244@warthog.procyon.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 928 Lines: 28 On Mon, Apr 03, 2017 at 08:20:44PM +0100, David Howells wrote: > Eric Biggers wrote: > > > > > - if (_payload) { > > > > + if (plen) { > > > > > > "if (_payload && plen)" would be better. > > > > > > David > > > > No, that doesn't solve the problem. The problem is that userspace can pass > > in a NULL payload with nonzero length, causing the kernel to dereference a > > NULL pointer for some key types. For example: > > Okay, in that case, I think there should be an else-statement that clears plen > if !_payload. > > David I think it's preferable to return EFAULT in the case in question. Most syscalls work like that, i.e. if you say you have 100 bytes (or any number > 0) at address NULL you'll get EFAULT. Also note that anyone doing this before would have been either crashing the kernel or getting EINVAL. So starting to return EFAULT would be very unlikely to break anything. - Eric