Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261652AbVEQP3C (ORCPT ); Tue, 17 May 2005 11:29:02 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261642AbVEQP2u (ORCPT ); Tue, 17 May 2005 11:28:50 -0400 Received: from e31.co.us.ibm.com ([32.97.110.129]:11211 "EHLO e31.co.us.ibm.com") by vger.kernel.org with ESMTP id S261644AbVEQP14 (ORCPT ); Tue, 17 May 2005 11:27:56 -0400 Date: Tue, 17 May 2005 10:27:51 -0500 From: Michael Halcrow To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Chris Wright , Serge Hallyn , mhalcrow@us.ibm.com Subject: [patch 4/7] BSD Secure Levels: memory alloc failure check Message-ID: <20050517152750.GC2944@halcrow.us> Reply-To: Michael Halcrow References: <20050517152303.GA2814@halcrow.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050517152303.GA2814@halcrow.us> User-Agent: Mutt/1.5.9i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1782 Lines: 49 This is the fourth in a series of seven patches to the BSD Secure Levels LSM. It adds a check for a memory allocation failure condition. Thanks to Vesa-Matti J Kari for pointing out this problem. Signed off by: Michael Halcrow Index: linux-2.6.12-rc4-mm2-seclvl/security/seclvl.c =================================================================== --- linux-2.6.12-rc4-mm2-seclvl.orig/security/seclvl.c 2005-05-16 16:28:19.000000000 -0500 +++ linux-2.6.12-rc4-mm2-seclvl/security/seclvl.c 2005-05-16 16:28:29.000000000 -0500 @@ -310,7 +310,7 @@ static int plaintext_to_sha1(unsigned char *hash, const char *plaintext, int len) { - char *pgVirtAddr; + char *pg_virt_addr; struct crypto_tfm *tfm; struct scatterlist sg[1]; if (len > PAGE_SIZE) { @@ -327,16 +327,20 @@ } // Just get a new page; don't play around with page boundaries // and scatterlists. - pgVirtAddr = (char *)__get_free_page(GFP_KERNEL); - sg[0].page = virt_to_page(pgVirtAddr); + pg_virt_addr = (char *)__get_free_page(GFP_KERNEL); + if (!pg_virt_addr) { + seclvl_printk(0, KERN_ERR "%s: Out of memory\n", __FUNCTION__); + return -ENOMEM; + } + sg[0].page = virt_to_page(pg_virt_addr); sg[0].offset = 0; sg[0].length = len; - strncpy(pgVirtAddr, plaintext, len); + strncpy(pg_virt_addr, plaintext, len); crypto_digest_init(tfm); crypto_digest_update(tfm, sg, 1); crypto_digest_final(tfm, hash); crypto_free_tfm(tfm); - free_page((unsigned long)pgVirtAddr); + free_page((unsigned long)pg_virt_addr); return 0; } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/