From patchwork Sun Oct 30 21:27:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Iooss X-Patchwork-Id: 9404687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D305460586 for ; Sun, 30 Oct 2016 21:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB63528E52 for ; Sun, 30 Oct 2016 21:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE55828E81; Sun, 30 Oct 2016 21:28:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from emsm-gh1-uea11.nsa.gov (smtp.nsa.gov [8.44.101.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6505728E52 for ; Sun, 30 Oct 2016 21:28:08 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.31,423,1473120000"; d="scan'208";a="337674" IronPort-PHdr: =?us-ascii?q?9a23=3AK5mjDhHWJzGJ/x1wjqEIiJ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ75os+wAkXT6L1XgUPTWs2DsrQf2rCQ7P+rADBfqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZv?= =?us-ascii?q?IaytQ8iJ3p7xiL/5osGMKyxzxxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP?= =?us-ascii?q?5Xz247bXianhL7+9vitMU7q3cYhuglv/Jkfe26Ov1gDO8QMDNzKG0x5cv2pTHf?= =?us-ascii?q?XACP4T0aSWxQnR1WUCbf6xSveJb6tS/zraJc3y6BJoWiS7E/XjCr9OFqTxjzkw?= =?us-ascii?q?8Cay5/93vY3J8jxJlHqQ6s8kQsi7XfZ5uYYb8nJq4=3D?= X-IPAS-Result: =?us-ascii?q?A2HYBQDIZBZY/wHyM5BdHQEFAQsBGAEFAQsBgn8BAQEBAR+?= =?us-ascii?q?BSgu0MIY9KYgJUwEBAQEBAQEBAgECXyiCMwQDEwWCGAI3FCAOAwkCFycCCAgDA?= =?us-ascii?q?S0VHwsFGASIMwQBv3GGPYhuEQFohHcdBYg+h0qKEIFqjjuKFIV7SZBKVFKDZYE?= =?us-ascii?q?8cYUjeIExAQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 30 Oct 2016 21:28:07 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u9ULRjrq004346; Sun, 30 Oct 2016 17:27:49 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u9ULRhIg217707 for ; Sun, 30 Oct 2016 17:27:43 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u9ULRh6U004344 for ; Sun, 30 Oct 2016 17:27:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BdAADIZBZYhyIeaIFdHQEFAQsBgyoBAQEBAYFpC7QwgjOELogOUwECAQEBAQECEwEBAQoLCQkdhmGBAohUBAGicpx/hj2JaIR3HQWIPodKihCBao47kA9JkEqBJoJfAQsBgjVxh0wBAQE X-IPAS-Result: A1BdAADIZBZYhyIeaIFdHQEFAQsBgyoBAQEBAYFpC7QwgjOELogOUwECAQEBAQECEwEBAQoLCQkdhmGBAohUBAGicpx/hj2JaIR3HQWIPodKihCBao47kA9JkEqBJoJfAQsBgjVxh0wBAQE X-IronPort-AV: E=Sophos;i="5.31,423,1473134400"; d="scan'208";a="5794681" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 30 Oct 2016 17:27:42 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AT63KTB1r+SN22dq0smDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?segVIvad9pjvdHbS+e9qxAeQG96KsbQb1KGP7/+ocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXsq3G/pQQfBg/4fVIs?= =?us-ascii?q?YL+kQMiN0I/ui7/60qaQSj0AvCC6b7J2IUf+hiTqne5Sv7FfLL0swADCuHpCdr?= =?us-ascii?q?ce72ppIVWOg0S0vZ/or9YwuxhX7uks889GTLXSY7UzTbseCi8vdW8y+p7Frx7G?= =?us-ascii?q?GC2O7XwYW35esx1PGBONuBf7VZD1uzC8t+16wzKyOJHmC7cuVmLxvO9QVBb0hX?= =?us-ascii?q?JfZHYC+2bNh5kogQ=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HCAADIZBZYhyIeaIFdHQEFAQsBGAEFA?= =?us-ascii?q?QsBgn8BAQEBAYFpC7QwgjOELogOUwEBAQEBAQEBAgECEAEBAQoLCQkdMIIzGIN?= =?us-ascii?q?mgQKIVAQBonKcf4Y9iWiEdx0FiD6HSooQgWqOO5APSZBKgSaCXwELAYI1cYdMA?= =?us-ascii?q?QEB?= X-IPAS-Result: =?us-ascii?q?A0HCAADIZBZYhyIeaIFdHQEFAQsBGAEFAQsBgn8BAQEBAYF?= =?us-ascii?q?pC7QwgjOELogOUwEBAQEBAQEBAgECEAEBAQoLCQkdMIIzGINmgQKIVAQBonKcf?= =?us-ascii?q?4Y9iWiEdx0FiD6HSooQgWqOO5APSZBKgSaCXwELAYI1cYdMAQEB?= X-IronPort-AV: E=Sophos;i="5.31,423,1473120000"; d="scan'208";a="337670" Received: from mx1.polytechnique.org ([129.104.30.34]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2016 21:27:42 +0000 Received: from eversmanni.numericable.fr (81-66-120-207.rev.numericable.fr [81.66.120.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id E92EF564864 for ; Sun, 30 Oct 2016 22:27:40 +0100 (CET) From: Nicolas Iooss To: selinux@tycho.nsa.gov Subject: [PATCH 1/1] policycoreutils: semodule_package: do not fail with an empty fc file Date: Sun, 30 Oct 2016 22:27:22 +0100 Message-Id: <20161030212722.24743-1-nicolas.iooss@m4x.org> X-Mailer: git-send-email 2.10.1 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sun Oct 30 22:27:41 2016 +0100 (CET)) X-Org-Mail: nicolas.iooss.2010@polytechnique.org X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP When running sepolgen tests on a Linux 4.7 kernel, one test fails with the following message: /usr/bin/semodule_package: Failed to mmap tmp/module_compile_test.mod.fc: Invalid argument The .fc file is empty, which is why it cannot be used with mmap(). Anyway the current code supports empty files (with if() conditions in main()) so do not try to mmap an empty file in file_to_data(). Signed-off-by: Nicolas Iooss --- While at it, it seems that neither seusersdata nor user_extradata are unmapped at the end of main(). As this does not cause a test to fail I will not send a patch to fix this. policycoreutils/semodule_package/semodule_package.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/policycoreutils/semodule_package/semodule_package.c b/policycoreutils/semodule_package/semodule_package.c index d2a5fd07bd71..e472054826a3 100644 --- a/policycoreutils/semodule_package/semodule_package.c +++ b/policycoreutils/semodule_package/semodule_package.c @@ -72,6 +72,10 @@ static int file_to_data(const char *path, char **data, size_t * len) path, strerror(errno)); goto err; } + if (!sb.st_size) { + *len = 0; + return 0; + } *data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (*data == MAP_FAILED) {