Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752129AbdFLCdk (ORCPT ); Sun, 11 Jun 2017 22:33:40 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47169 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752002AbdFLCdh (ORCPT ); Sun, 11 Jun 2017 22:33:37 -0400 Subject: Re: [PATCH v1] shebang: restrict python interactive prompt/interpreter From: Mimi Zohar To: =?ISO-8859-1?Q?Micka=EBl_Sala=FCn?= , Tetsuo Handa , keescook@chromium.org, matt@nmatt.com Cc: jason@perfinion.com, linux-security-module@vger.kernel.org, Daniel Micay , kernel-hardening , LKML Date: Sun, 11 Jun 2017 22:32:37 -0400 In-Reply-To: References: <201706100041.GFH78616.OFtOHFJSLQOMVF@I-love.SAKURA.ne.jp> <754b78d1-f7f9-58bd-bf74-fea9e105649a@nmatt.com> <20170609164315.GA1141@meriadoc.perfinion.com> <201706101427.EEG90168.OtFFHSFMOVOJQL@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-MML: disable x-cbid: 17061202-0044-0000-0000-0000026AF842 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17061202-0045-0000-0000-000006FA151D Message-Id: <1497234757.21594.280.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-12_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706120041 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3342 Lines: 73 On Sun, 2017-06-11 at 13:44 +0200, Mickaël Salaün wrote: > On 10/06/2017 07:27, Tetsuo Handa wrote: > > Kees Cook wrote: > >> On Fri, Jun 9, 2017 at 10:23 AM, Matt Brown wrote: > >>> what does everyone thing about a envp_blacklist option that is a list of > >>> environmental variables that will be stripped from exec calls. This can > >>> be done in the LSM hook bprm_check_security. > >>> > >>> Is there any reason on a hardened system why you would need the > >>> PYTHONINSPECT environmental variable? > >> > >> As part of shebang, it likely makes sense to whitelist (rather than > >> blacklist) the env of the restricted interpreters. Though this is > >> starting to get complex. :P > > > > Blacklisting environment variables is dangerous. I think that > > administrators can afford whitelisting environment variable names. > > I think that implementing whitelist of environment variable names > > as an independent LSM module would be fine. > > > > While it is true that things starts getting complex if we check environment > > variables, shebang will already become complex if it starts worrying about > > updating inode number list in order to close the race window between doing > > creat()+write()+close()+chmod()+rename() by the package manager and teaching > > the kernel the new inode number determined by creat(). We will need an > > interface for allowing the package manager to teach the kernel the new inode > > number and modification of the package manager, for the kernel side is doing > > inode number based blacklisting while user side can execute it before rename(). I don't think we're trying to protect against executing the interpreter prior to the rename.  Rename, itself, would trigger associating the interpreter name with an inode number. > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-security-module" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html > > > > Using filesystem xattr seems like a good idea for this kind of > exceptions and instead of a hardcoded interpreter path. Something like > "security.tpe.interpreter=1|2" (bitmask for interpreter-only and/or CLI) > and "security.tpe.environment=HOME,LOGNAME" would be quite flexible to > configure a security policy for some binaries. This could also be > protected by IMA/EVM, if needed. Checking for the existence of an xattr without caching is relatively slow.  I'm not sure that we would want to go this route. > This kind of xattr should be writable by the owner of the file. The TPE > LSM [1] could then take these xattr into account according to the TPE > policy. Security xattrs are only writable by root. Mimi > The "security.tpe.environment" could also be set on a script file to be > part of the union with the interpreter's environment whitelist. This may > be needed to be able to use environment variables as configuration in a > script. > > In the future, a "security.tpe.memory" could contain a set of flags as > PaX uses for mprotect-like exceptions (user.pax.flags). > > Userland daemons such as paxctld or paxrat could be used (with some > tweaks) to keep a consistent TPE policy over time. > > Mickaël > > > [1] https://lkml.kernel.org/r/1497015878.21594.201.camel@linux.vnet.ibm.com >