From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754855AbZGUKRv (ORCPT ); Tue, 21 Jul 2009 06:17:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754710AbZGUKRu (ORCPT ); Tue, 21 Jul 2009 06:17:50 -0400 Received: from bu3sch.de ([62.75.166.246]:56947 "EHLO vs166246.vserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754661AbZGUKRu (ORCPT ); Tue, 21 Jul 2009 06:17:50 -0400 From: Michael Buesch To: Henrique de Moraes Holschuh Subject: Re: [PATCH] thinkpad-acpi: Avoid heap buffer overrun Date: Tue, 21 Jul 2009 12:17:47 +0200 User-Agent: KMail/1.9.9 Cc: ibm-acpi-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <200907211216.18135.mb@bu3sch.de> In-Reply-To: <200907211216.18135.mb@bu3sch.de> X-Move-Along: Nothing to see here. No, really... Nothing. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907211217.47484.mb@bu3sch.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 21 July 2009 12:16:17 Michael Buesch wrote: > Avoid a heap buffer overrun triggered by an integer overflow of the userspace > controlled "count" variable. > If userspace passes in a "count" of (size_t)-1l, the kmalloc size will overflow > to ((size_t)-1l + 2) = 1, so only one byte will be allocated. However, copy_from_user() > will attempt to copy 0xFFFFFFFF (or 0xFFFFFFFFFFFFFFFF on 64bit) bytes to the buffer. > > A possible testcase could look like this: > > #include > #include > #include > #include > > int main(int argc, char **argv) > { > int fd; > char c; > > if (argc != 2) { > printf("Usage: %s /proc/acpi/ibm/filename\n", argv[0]); > return 1; > } > fd = open(argv[1], O_RDWR); > if (fd < 0) { > printf("Could not open proc file\n"); > return 1; > } > write(fd, &c, (size_t)-1l); > } > > We avoid the integer overrun by putting an arbitrary limit on the count. > PAGE_SIZE sounds like a sane limit. > > Signed-off-by: Michael Buesch Whoops, forgot Cc: stable@kernel.org -- Greetings, Michael.