From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by kanga.kvack.org (Postfix) with ESMTP id 052996B0085 for ; Wed, 4 Jun 2014 19:31:35 -0400 (EDT) Received: by mail-wg0-f49.google.com with SMTP id m15so209960wgh.8 for ; Wed, 04 Jun 2014 16:31:35 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id u2si8000778wjy.107.2014.06.04.16.31.33 for ; Wed, 04 Jun 2014 16:31:34 -0700 (PDT) Date: Wed, 4 Jun 2014 19:31:22 -0400 From: Dave Jones Subject: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140604233122.GA19838@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: owner-linux-mm@kvack.org List-ID: To: Linux Kernel Cc: mtk.manpages@gmail.com, linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com I just noticed that trinity was freaking out in places when mmap was returning zero. This surprised me, because I had the mmap_min_addr sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. There's no mention of this return value in the man page, so I dug into the kernel code, and it appears that we do.. sys_mmap vm_mmap_pgoff security_mmap_file ima_file_mmap <- returns 0 if not PROT_EXEC and then the 0 gets propagated up as a retval all the way to userspace. It smells to me like we might be violating a standard or two here, and instead of 0 ima should be returning -Esomething thoughts? Dave -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by kanga.kvack.org (Postfix) with ESMTP id 8DD646B004D for ; Thu, 5 Jun 2014 00:40:46 -0400 (EDT) Received: by mail-we0-f178.google.com with SMTP id x48so205874wes.9 for ; Wed, 04 Jun 2014 21:40:45 -0700 (PDT) Received: from mail-we0-x236.google.com (mail-we0-x236.google.com [2a00:1450:400c:c03::236]) by mx.google.com with ESMTPS id ff4si39056926wib.70.2014.06.04.21.40.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 21:40:45 -0700 (PDT) Received: by mail-we0-f182.google.com with SMTP id t60so427440wes.13 for ; Wed, 04 Jun 2014 21:40:44 -0700 (PDT) Message-ID: <538FF4C4.5090300@gmail.com> Date: Thu, 05 Jun 2014 06:40:36 +0200 From: "Michael Kerrisk (man-pages)" MIME-Version: 1.0 Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. References: <20140604233122.GA19838@redhat.com> In-Reply-To: <20140604233122.GA19838@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Dave Jones , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com Cc: mtk.manpages@gmail.com On 06/05/2014 01:31 AM, Dave Jones wrote: > I just noticed that trinity was freaking out in places when mmap was > returning zero. This surprised me, because I had the mmap_min_addr > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > There's no mention of this return value in the man page, so I dug > into the kernel code, and it appears that we do.. > > sys_mmap > vm_mmap_pgoff > security_mmap_file > ima_file_mmap <- returns 0 if not PROT_EXEC > > and then the 0 gets propagated up as a retval all the way to userspace. > > It smells to me like we might be violating a standard or two here, and > instead of 0 ima should be returning -Esomething > > thoughts? Seems like either EACCESS or ENOTSUP is appropriate; here's the pieces from POSIX: EACCES The fildes argument is not open for read, regardless of the protection specified, or fildes is not open for write and PROT_WRITE was specified for a MAP_SHARED type mapping. ENOTSUP The implementation does not support the combination of accesses requested in the prot argument. ENOTSUP seems to be more appropriate in my reading of the above, though I'd somehow more have expected EACCES. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by kanga.kvack.org (Postfix) with ESMTP id 5EC906B0035 for ; Thu, 5 Jun 2014 11:57:50 -0400 (EDT) Received: by mail-wi0-f177.google.com with SMTP id f8so3743906wiw.16 for ; Thu, 05 Jun 2014 08:57:48 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id pg7si12112301wjb.56.2014.06.05.08.57.19 for ; Thu, 05 Jun 2014 08:57:20 -0700 (PDT) Date: Thu, 5 Jun 2014 11:56:58 -0400 From: Dave Jones Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140605155658.GA22673@redhat.com> References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <538FF4C4.5090300@gmail.com> Sender: owner-linux-mm@kvack.org List-ID: To: "Michael Kerrisk (man-pages)" Cc: Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > On 06/05/2014 01:31 AM, Dave Jones wrote: > > I just noticed that trinity was freaking out in places when mmap was > > returning zero. This surprised me, because I had the mmap_min_addr > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > There's no mention of this return value in the man page, so I dug > > into the kernel code, and it appears that we do.. > > > > sys_mmap > > vm_mmap_pgoff > > security_mmap_file > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > It smells to me like we might be violating a standard or two here, and > > instead of 0 ima should be returning -Esomething > > > > thoughts? > > Seems like either EACCESS or ENOTSUP is appropriate; here's the pieces > from POSIX: > > EACCES The fildes argument is not open for read, regardless of > the protection specified, or fildes is not open for > write and PROT_WRITE was specified for a MAP_SHARED type > mapping. > > ENOTSUP > The implementation does not support the combination > of accesses requested in the prot argument. > > ENOTSUP seems to be more appropriate in my reading of the above, though > I'd somehow more have expected EACCES. I just realised that this affects even kernels with CONFIG_IMA unset, because there we just do 'return 0' unconditionally. Also, it appears that kernels with CONFIG_SECURITY unset will also return a zero for the same reason. This is kind of a mess, and has been that way for a long time. Fixing this will require user-visible breakage, but in this case I think it's justified as there's no way an app can do the right thing if it gets a 0 back. Linus ? Dave -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by kanga.kvack.org (Postfix) with ESMTP id E13B56B0037 for ; Thu, 5 Jun 2014 12:21:22 -0400 (EDT) Received: by mail-wg0-f52.google.com with SMTP id l18so1412391wgh.35 for ; Thu, 05 Jun 2014 09:21:22 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id dk2si15991511wib.78.2014.06.05.09.21.02 for ; Thu, 05 Jun 2014 09:21:03 -0700 (PDT) Date: Thu, 5 Jun 2014 12:20:45 -0400 From: Dave Jones Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140605162045.GA25474@redhat.com> References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140605155658.GA22673@redhat.com> Sender: owner-linux-mm@kvack.org List-ID: To: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com On Thu, Jun 05, 2014 at 11:56:58AM -0400, Dave Jones wrote: > On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > > On 06/05/2014 01:31 AM, Dave Jones wrote: > > > I just noticed that trinity was freaking out in places when mmap was > > > returning zero. This surprised me, because I had the mmap_min_addr > > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > > > There's no mention of this return value in the man page, so I dug > > > into the kernel code, and it appears that we do.. > > > > > > sys_mmap > > > vm_mmap_pgoff > > > security_mmap_file > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > I just realised that this affects even kernels with CONFIG_IMA unset, > because there we just do 'return 0' unconditionally. > > Also, it appears that kernels with CONFIG_SECURITY unset will also > return a zero for the same reason. Hang on, I was misreading that whole security_mmap_file ret handling code. There's something else at work here. I'll dig and get a reproducer. Dave -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by kanga.kvack.org (Postfix) with ESMTP id 5528E6B0035 for ; Thu, 5 Jun 2014 21:49:35 -0400 (EDT) Received: by mail-qg0-f47.google.com with SMTP id j107so3089233qga.20 for ; Thu, 05 Jun 2014 18:49:35 -0700 (PDT) Received: from e38.co.us.ibm.com (e38.co.us.ibm.com. [32.97.110.159]) by mx.google.com with ESMTPS id l10si13919930yhm.173.2014.06.05.18.49.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 05 Jun 2014 18:49:34 -0700 (PDT) Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Jun 2014 19:49:32 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id B5F863E40044 for ; Thu, 5 Jun 2014 19:49:30 -0600 (MDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by b03cxnp08026.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s561mVsS7012738 for ; Fri, 6 Jun 2014 03:48:32 +0200 Received: from d03av02.boulder.ibm.com (localhost [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s561nUZu001431 for ; Thu, 5 Jun 2014 19:49:30 -0600 Message-ID: <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. From: Mimi Zohar Date: Thu, 05 Jun 2014 21:49:29 -0400 In-Reply-To: <20140605162045.GA25474@redhat.com> References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> <20140605162045.GA25474@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Dave Jones Cc: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds On Thu, 2014-06-05 at 12:20 -0400, Dave Jones wrote: > On Thu, Jun 05, 2014 at 11:56:58AM -0400, Dave Jones wrote: > > On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > > > On 06/05/2014 01:31 AM, Dave Jones wrote: > > > > I just noticed that trinity was freaking out in places when mmap was > > > > returning zero. This surprised me, because I had the mmap_min_addr > > > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > > > > > There's no mention of this return value in the man page, so I dug > > > > into the kernel code, and it appears that we do.. > > > > > > > > sys_mmap > > > > vm_mmap_pgoff > > > > security_mmap_file > > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > I just realised that this affects even kernels with CONFIG_IMA unset, > > because there we just do 'return 0' unconditionally. > > > > Also, it appears that kernels with CONFIG_SECURITY unset will also > > return a zero for the same reason. > > Hang on, I was misreading that whole security_mmap_file ret handling code. > There's something else at work here. I'll dig and get a reproducer. According to security.h, it should return 0 if permission is granted. If IMA is not enabled, it should also return 0. What exactly is the problem? thanks, Mimi -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by kanga.kvack.org (Postfix) with ESMTP id 08C816B0035 for ; Thu, 5 Jun 2014 21:56:21 -0400 (EDT) Received: by mail-wi0-f169.google.com with SMTP id ho1so117185wib.2 for ; Thu, 05 Jun 2014 18:56:21 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id d16si44804624wiv.38.2014.06.05.18.56.20 for ; Thu, 05 Jun 2014 18:56:20 -0700 (PDT) Date: Thu, 5 Jun 2014 21:56:10 -0400 From: Dave Jones Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140606015610.GA23041@redhat.com> References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> <20140605162045.GA25474@redhat.com> <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Mimi Zohar Cc: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds On Thu, Jun 05, 2014 at 09:49:29PM -0400, Mimi Zohar wrote: > > > > > There's no mention of this return value in the man page, so I dug > > > > > into the kernel code, and it appears that we do.. > > > > > > > > > > sys_mmap > > > > > vm_mmap_pgoff > > > > > security_mmap_file > > > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > > > I just realised that this affects even kernels with CONFIG_IMA unset, > > > because there we just do 'return 0' unconditionally. > > > > > > Also, it appears that kernels with CONFIG_SECURITY unset will also > > > return a zero for the same reason. > > > > Hang on, I was misreading that whole security_mmap_file ret handling code. > > There's something else at work here. I'll dig and get a reproducer. > > According to security.h, it should return 0 if permission is granted. > If IMA is not enabled, it should also return 0. What exactly is the > problem? Still digging. I managed to get this to reproduce constantly last night, but no luck today. From re-reading the code though, I think IMA/lsm isn't the problem. Dave -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754658AbaFDXbi (ORCPT ); Wed, 4 Jun 2014 19:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36331 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754644AbaFDXbg (ORCPT ); Wed, 4 Jun 2014 19:31:36 -0400 Date: Wed, 4 Jun 2014 19:31:22 -0400 From: Dave Jones To: Linux Kernel Cc: mtk.manpages@gmail.com, linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com Subject: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140604233122.GA19838@redhat.com> Mail-Followup-To: Dave Jones , Linux Kernel , mtk.manpages@gmail.com, linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I just noticed that trinity was freaking out in places when mmap was returning zero. This surprised me, because I had the mmap_min_addr sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. There's no mention of this return value in the man page, so I dug into the kernel code, and it appears that we do.. sys_mmap vm_mmap_pgoff security_mmap_file ima_file_mmap <- returns 0 if not PROT_EXEC and then the 0 gets propagated up as a retval all the way to userspace. It smells to me like we might be violating a standard or two here, and instead of 0 ima should be returning -Esomething thoughts? Dave From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753869AbaFEEks (ORCPT ); Thu, 5 Jun 2014 00:40:48 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:41395 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753333AbaFEEkp (ORCPT ); Thu, 5 Jun 2014 00:40:45 -0400 Message-ID: <538FF4C4.5090300@gmail.com> Date: Thu, 05 Jun 2014 06:40:36 +0200 From: "Michael Kerrisk (man-pages)" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Dave Jones , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com CC: mtk.manpages@gmail.com Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. References: <20140604233122.GA19838@redhat.com> In-Reply-To: <20140604233122.GA19838@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/05/2014 01:31 AM, Dave Jones wrote: > I just noticed that trinity was freaking out in places when mmap was > returning zero. This surprised me, because I had the mmap_min_addr > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > There's no mention of this return value in the man page, so I dug > into the kernel code, and it appears that we do.. > > sys_mmap > vm_mmap_pgoff > security_mmap_file > ima_file_mmap <- returns 0 if not PROT_EXEC > > and then the 0 gets propagated up as a retval all the way to userspace. > > It smells to me like we might be violating a standard or two here, and > instead of 0 ima should be returning -Esomething > > thoughts? Seems like either EACCESS or ENOTSUP is appropriate; here's the pieces from POSIX: EACCES The fildes argument is not open for read, regardless of the protection specified, or fildes is not open for write and PROT_WRITE was specified for a MAP_SHARED type mapping. ENOTSUP The implementation does not support the combination of accesses requested in the prot argument. ENOTSUP seems to be more appropriate in my reading of the above, though I'd somehow more have expected EACCES. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751843AbaFEP5w (ORCPT ); Thu, 5 Jun 2014 11:57:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57660 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750866AbaFEP5u (ORCPT ); Thu, 5 Jun 2014 11:57:50 -0400 Date: Thu, 5 Jun 2014 11:56:58 -0400 From: Dave Jones To: "Michael Kerrisk (man-pages)" Cc: Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140605155658.GA22673@redhat.com> Mail-Followup-To: Dave Jones , "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <538FF4C4.5090300@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > On 06/05/2014 01:31 AM, Dave Jones wrote: > > I just noticed that trinity was freaking out in places when mmap was > > returning zero. This surprised me, because I had the mmap_min_addr > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > There's no mention of this return value in the man page, so I dug > > into the kernel code, and it appears that we do.. > > > > sys_mmap > > vm_mmap_pgoff > > security_mmap_file > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > It smells to me like we might be violating a standard or two here, and > > instead of 0 ima should be returning -Esomething > > > > thoughts? > > Seems like either EACCESS or ENOTSUP is appropriate; here's the pieces > from POSIX: > > EACCES The fildes argument is not open for read, regardless of > the protection specified, or fildes is not open for > write and PROT_WRITE was specified for a MAP_SHARED type > mapping. > > ENOTSUP > The implementation does not support the combination > of accesses requested in the prot argument. > > ENOTSUP seems to be more appropriate in my reading of the above, though > I'd somehow more have expected EACCES. I just realised that this affects even kernels with CONFIG_IMA unset, because there we just do 'return 0' unconditionally. Also, it appears that kernels with CONFIG_SECURITY unset will also return a zero for the same reason. This is kind of a mess, and has been that way for a long time. Fixing this will require user-visible breakage, but in this case I think it's justified as there's no way an app can do the right thing if it gets a 0 back. Linus ? Dave From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752051AbaFEQVY (ORCPT ); Thu, 5 Jun 2014 12:21:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1616 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751640AbaFEQVX (ORCPT ); Thu, 5 Jun 2014 12:21:23 -0400 Date: Thu, 5 Jun 2014 12:20:45 -0400 From: Dave Jones To: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140605162045.GA25474@redhat.com> Mail-Followup-To: Dave Jones , "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds , zohar@linux.vnet.ibm.com References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140605155658.GA22673@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 05, 2014 at 11:56:58AM -0400, Dave Jones wrote: > On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > > On 06/05/2014 01:31 AM, Dave Jones wrote: > > > I just noticed that trinity was freaking out in places when mmap was > > > returning zero. This surprised me, because I had the mmap_min_addr > > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > > > There's no mention of this return value in the man page, so I dug > > > into the kernel code, and it appears that we do.. > > > > > > sys_mmap > > > vm_mmap_pgoff > > > security_mmap_file > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > I just realised that this affects even kernels with CONFIG_IMA unset, > because there we just do 'return 0' unconditionally. > > Also, it appears that kernels with CONFIG_SECURITY unset will also > return a zero for the same reason. Hang on, I was misreading that whole security_mmap_file ret handling code. There's something else at work here. I'll dig and get a reproducer. Dave From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752966AbaFFBtf (ORCPT ); Thu, 5 Jun 2014 21:49:35 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:56641 "EHLO e33.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751677AbaFFBte (ORCPT ); Thu, 5 Jun 2014 21:49:34 -0400 Message-ID: <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. From: Mimi Zohar To: Dave Jones Cc: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds Date: Thu, 05 Jun 2014 21:49:29 -0400 In-Reply-To: <20140605162045.GA25474@redhat.com> References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> <20140605162045.GA25474@redhat.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.6.4 (3.6.4-3.fc18) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14060601-0928-0000-0000-00000273A9D5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2014-06-05 at 12:20 -0400, Dave Jones wrote: > On Thu, Jun 05, 2014 at 11:56:58AM -0400, Dave Jones wrote: > > On Thu, Jun 05, 2014 at 06:40:36AM +0200, Michael Kerrisk (man-pages) wrote: > > > On 06/05/2014 01:31 AM, Dave Jones wrote: > > > > I just noticed that trinity was freaking out in places when mmap was > > > > returning zero. This surprised me, because I had the mmap_min_addr > > > > sysctl set to 64k, so it wasn't a MAP_FIXED mapping that did it. > > > > > > > > There's no mention of this return value in the man page, so I dug > > > > into the kernel code, and it appears that we do.. > > > > > > > > sys_mmap > > > > vm_mmap_pgoff > > > > security_mmap_file > > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > I just realised that this affects even kernels with CONFIG_IMA unset, > > because there we just do 'return 0' unconditionally. > > > > Also, it appears that kernels with CONFIG_SECURITY unset will also > > return a zero for the same reason. > > Hang on, I was misreading that whole security_mmap_file ret handling code. > There's something else at work here. I'll dig and get a reproducer. According to security.h, it should return 0 if permission is granted. If IMA is not enabled, it should also return 0. What exactly is the problem? thanks, Mimi From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753095AbaFFB40 (ORCPT ); Thu, 5 Jun 2014 21:56:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3641 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753046AbaFFB4X (ORCPT ); Thu, 5 Jun 2014 21:56:23 -0400 Date: Thu, 5 Jun 2014 21:56:10 -0400 From: Dave Jones To: Mimi Zohar Cc: "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds Subject: Re: ima_mmap_file returning 0 to userspace as mmap result. Message-ID: <20140606015610.GA23041@redhat.com> Mail-Followup-To: Dave Jones , Mimi Zohar , "Michael Kerrisk (man-pages)" , Linux Kernel , linux-mm@kvack.org, Linus Torvalds References: <20140604233122.GA19838@redhat.com> <538FF4C4.5090300@gmail.com> <20140605155658.GA22673@redhat.com> <20140605162045.GA25474@redhat.com> <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1402019369.5458.55.camel@dhcp-9-2-203-236.watson.ibm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 05, 2014 at 09:49:29PM -0400, Mimi Zohar wrote: > > > > > There's no mention of this return value in the man page, so I dug > > > > > into the kernel code, and it appears that we do.. > > > > > > > > > > sys_mmap > > > > > vm_mmap_pgoff > > > > > security_mmap_file > > > > > ima_file_mmap <- returns 0 if not PROT_EXEC > > > > > > > > > > and then the 0 gets propagated up as a retval all the way to userspace. > > > > > > I just realised that this affects even kernels with CONFIG_IMA unset, > > > because there we just do 'return 0' unconditionally. > > > > > > Also, it appears that kernels with CONFIG_SECURITY unset will also > > > return a zero for the same reason. > > > > Hang on, I was misreading that whole security_mmap_file ret handling code. > > There's something else at work here. I'll dig and get a reproducer. > > According to security.h, it should return 0 if permission is granted. > If IMA is not enabled, it should also return 0. What exactly is the > problem? Still digging. I managed to get this to reproduce constantly last night, but no luck today. From re-reading the code though, I think IMA/lsm isn't the problem. Dave