Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp352233imm; Fri, 1 Jun 2018 01:58:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLcETv9v5f6Qgj/r0R4XT9wSb9dOgiX0u3XBgHP8qRgYiwwuqu/Y114KYfThhwkRnpsxVQu X-Received: by 2002:a17:902:bd95:: with SMTP id q21-v6mr9966376pls.237.1527843491475; Fri, 01 Jun 2018 01:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527843491; cv=none; d=google.com; s=arc-20160816; b=rIYLueZ7YN8ZHQt/nxwDdtOQ+QmYfZc1QCOnl0YR4O9LJlhoq68ZIEBylWTkYqkylI 7rv/K9exMcK8KxApLV5DiC4CMiadEfE3wEM8Wf9yet6H5wt6KeUqqknLt1c/CJsJFrn0 9jQGqvYrRLa95yNq50aknHxOXD+bjJ4Pbv5daVGSfGag6hxGdFBNBLynzoMf/RV9LsVI vozxi4UdjbOes8iTOTt64h+q3baz03UjLlGLMG8hMLX4vxMntxLYIJOmCXIeBs/kWVTj SD/60ap4J2axcXbTM1jnNLGPCC/iqBOJHZ2TiZSuel2KAAIDLsy+3PB+zDzsV/bgMhJm czcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :content-transfer-encoding:date:message-id:in-reply-to:cc:to:from :reply-to:subject:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=PSWT80C2y7+841HcjiLUXC+shQSMZ/CtbONgquPZFlk=; b=NptoDi/rRdLdjjgED005tzXCUVK7zovNThJeLw3yeaO+tZjd+dZUzmUHdjHHcgdzEK /ACBm86u4WSuEpimi7rqFn63eo0fUStvwAkrfjqLPbnDc2Fn0md2VKEjLmFpnSoNiur/ Dn0Ho4rVzyIhYf99P/+b5QKHb12d7gzgHKBqS68IZNnGaOpH/JS9oD/GSe0Nk+1yzb8Y 4bXrVJEG5Ydz4i8cc+grjOJxc6TN/DjWIy6P5MFAxX1aEFO1jxORuyvra9yJ/f3OCVYG pZ9vP9i2/Ued3h6WHWodJGdT1hwpddogkYlCoqJhVvzOzY98CAcNt+Dk+k5QenCMYgmU 9DYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OaSZuT0H; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si38468741plt.325.2018.06.01.01.57.57; Fri, 01 Jun 2018 01:58:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OaSZuT0H; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750866AbeFAI4V (ORCPT + 99 others); Fri, 1 Jun 2018 04:56:21 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:39213 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbeFAI4P (ORCPT ); Fri, 1 Jun 2018 04:56:15 -0400 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20180601085613epoutp0454536ff0e7f49a5796c3d3a73aebc599~z-XP__kiV1184811848epoutp04j for ; Fri, 1 Jun 2018 08:56:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20180601085613epoutp0454536ff0e7f49a5796c3d3a73aebc599~z-XP__kiV1184811848epoutp04j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1527843373; bh=PSWT80C2y7+841HcjiLUXC+shQSMZ/CtbONgquPZFlk=; h=Subject:Reply-To:From:To:CC:In-Reply-To:Date:References:From; b=OaSZuT0H8FlB8UDRG9TESP5uzEsqY0CbtVGBKSW/fW4LZTWF8n8odr0NjQBKjQscb VuDIw47Xo/LhC/reJkLrWYKxSpn+gt8fhhtNJbdYPbQgcGQ6hmjMa6S22DQB6ijEb+ tJWWtdJZeBjyTViQMn+0GrZsd2r6z8nttn3tn8mE= Received: from epsmges5p2new.samsung.com (unknown [182.195.40.198]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20180601085610epcas5p15edd6ec8ae24fce238ba1f36313ef1ec~z-XNlFTX71237412374epcas5p1i; Fri, 1 Jun 2018 08:56:10 +0000 (GMT) X-AuditID: b6c32a4a-abdff70000001139-5e-5b110a2a45b0 Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 02.42.04409.A2A011B5; Fri, 1 Jun 2018 17:56:10 +0900 (KST) Mime-Version: 1.0 Subject: RE: Re: [PATCH 1/1] Fix memory leak in kernfs_security_xattr_set and kernfs_security_xattr_set Reply-To: chandan.vn@samsung.com From: CHANDAN VN To: Tejun Heo , Casey Schaufler CC: "gregkh@linuxfoundation.org" , "bfields@fieldses.org" , "jlayton@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-nfs@vger.kernel.org" , CPGS , Sireesha Talluri , Chris Wright , "linux-security-module@vger.kernel.org" X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: <1ced6bce-92cc-7e0c-fab4-0aaa3d03b82f@schaufler-ca.com> X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20180601085609epcms5p5fefac0156a4816e9e48751211ab595ee@epcms5p5> Date: Fri, 01 Jun 2018 14:26:09 +0530 X-CMS-MailID: 20180601085609epcms5p5fefac0156a4816e9e48751211ab595ee Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-CPGSPASS: Y CMS-TYPE: 105P X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa1BMYRjHvXu2s6dYTmsbbzFm57iWKXuWrVMjaTTaITPN+ILFOlOv3R27 Z3f2bCk+CBMjioaMyV0XpEQlq0VaFiNREtMYjdwvmVIh13H2Nnx6f+9//s91HgKTVeMRhJGz IxvHmig8RNx4I3JmdFRIqFZZ9m06827/Sqan8QfOFD4tx5j3rkhmW1ktznyvrJIwnU2Hcab9 emsQM7D7Bc40tVuZH6fcYMFozfmSrbimrmonrmk+Ui3RFDVUAY27+SSuabxSgGmG6ianS1ai eQbEZiKbAnEZlkwjp0+klizTLdSpY5V0NB3PxFEKjjWjRColLT16kdEkdEgpsllTliClszxP zZ4/z2bJsiOFwcLbEyktTatiaGVcjEolvOrVCSq1YFmLDNsf3sGshybl3N9eJMkDzokFIJiA 5Fw4uOWypACEEDLSCeAr56DwIQgpGQp/O8Z7PONJI+zN7wrysIxUwJt9NWKfPgsW3OjzMk5G wjtHD0g8LCdT4Zu9LUGenBj5GIO1e3YDXzEpPLjjtdjHE+GlUxe9ejCZAkcG6/16GOw++0kS 4P5bx/yxcpjf04b5OBQ+/+4EgTynaxr8sRZY11nv7R+SObDnarhPjoMvu+tFHpaSS2GH6xDu YTE5Dd7rbBb5PCnwylCXV8eEuSpPfMQ8aTBhrtqm2YHu8y78lPgsY2Hhz1eigO44GuCp8M/H Cj9HwI5HX/2sgR/yT2K+NQ+LoNvhxPcCRem/TZf+V7n0X+XjAKsC4cjKm/WIV1tVHNoQw7Nm PovTx2RYzHXAe6lRix2g8n6aC5AEoMZIZw6P08qC2Gw+1+wCkMAouXR/tiBJM9ncjchm0dmy TIh3AbWwg2IsIizDItw9Z9fRalVsrDJeqZ7DxNLUBOnIE1IrI/WsHa1HyIpsgTgRERyRB1Ir dDNaNonEFdWO9lZ7YUtc2sX25u4zvW0LZw0/TihJIbQ47GXPFauKW9dIbzd+wZu48FUD7Oqv dz8nvzY3JD+Qt3b1vzThW0qXJoUtBzVOp2H+4LPkfSG518KX7Co/Vstyv84afyUh1/GRzW3u KaPcqfKohLc5JWJ6RUd+/DpKzBtYOgqz8exfuWWWXb8DAAA= DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180531092848epcas1p24b638ccd6da00f1e039bdb64de7e1a5b References: <1ced6bce-92cc-7e0c-fab4-0aaa3d03b82f@schaufler-ca.com> <1527758911-18610-1-git-send-email-chandan.vn@samsung.com> <20180531153943.GR1351649@devbig577.frc2.facebook.com> <4f00f9ae-3302-83b9-c083-d21ade380eb2@schaufler-ca.com> <20180531161107.GV1351649@devbig577.frc2.facebook.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi =C2=A0=0D=0A=0D=0A>On=C2=A05/31/2018=C2=A09:11=C2=A0AM,=C2=A0Tejun=C2=A0Heo= =C2=A0wrote:=0D=0A>=C2=A0On=C2=A0Thu,=C2=A0May=C2=A031,=C2=A02018=C2=A0at= =C2=A009:04:25AM=C2=A0-0700,=C2=A0Casey=C2=A0Schaufler=C2=A0wrote:=0D=0A>>>= =C2=A0On=C2=A05/31/2018=C2=A08:39=C2=A0AM,=C2=A0Tejun=C2=A0Heo=C2=A0wrote:= =0D=0A>>>>=C2=A0(cc'ing=C2=A0more=C2=A0security=C2=A0folks=C2=A0and=C2=A0co= pying=C2=A0whole=C2=A0body)=0D=0A>>>>=0D=0A>>>>=C2=A0So,=C2=A0I'm=C2=A0sure= =C2=A0the=C2=A0patch=C2=A0fixes=C2=A0the=C2=A0memory=C2=A0leak=C2=A0but=C2= =A0API=C2=A0wise=C2=A0it=C2=A0looks=0D=0A>>>>=C2=A0super=C2=A0confusing.=C2= =A0=C2=A0Can=C2=A0security=C2=A0folks=C2=A0chime=C2=A0in=C2=A0here?=C2=A0= =C2=A0Is=C2=A0this=C2=A0the=C2=A0right=0D=0A>>>>=C2=A0fix?=0D=0A>>>>=C2=A0s= ecurity_inode_getsecctx()=C2=A0provides=C2=A0a=C2=A0security=C2=A0context.= =C2=A0Technically,=0D=0A>>>>=C2=A0this=C2=A0is=C2=A0a=C2=A0data=C2=A0blob,= =C2=A0although=C2=A0both=C2=A0provider=C2=A0provide=C2=A0a=C2=A0null=C2=A0t= erminated=0D=0A>>>>=C2=A0string.=C2=A0security_inode_getsecurity(),=C2=A0on= =C2=A0the=C2=A0other=C2=A0hand,=C2=A0provides=C2=A0a=0D=0A>>>>=C2=A0string= =C2=A0to=C2=A0match=C2=A0an=C2=A0attribute=C2=A0name.=C2=A0The=C2=A0former= =C2=A0releases=C2=A0the=C2=A0security=0D=0A>>>>=C2=A0context=C2=A0with=C2= =A0security_release_secctx(),=C2=A0where=C2=A0the=C2=A0later=C2=A0releases= =C2=A0the=0D=0A>>>>=C2=A0string=C2=A0with=C2=A0kfree().=0D=0A>>>>=0D=0A>>>>= =C2=A0When=C2=A0the=C2=A0Smack=C2=A0hook=C2=A0smack_inode_getsecctx()=C2=A0= was=C2=A0added=C2=A0in=C2=A02009=0D=0A>>>>=C2=A0for=C2=A0use=C2=A0by=C2=A0l= abeled=C2=A0NFS=C2=A0the=C2=A0alloc=C2=A0value=C2=A0passed=C2=A0to=0D=0A>>>= =C2=A0smack_inode_getsecurity()=C2=A0was=C2=A0set=C2=A0incorrectly.=C2=A0Th= is=C2=A0wasn't=C2=A0a=0D=0A>>>=C2=A0major=C2=A0issue,=C2=A0since=C2=A0label= ed=C2=A0NFS=C2=A0is=C2=A0a=C2=A0fringe=C2=A0case.=C2=A0When=C2=A0kernfs=0D= =0A>>>=C2=A0started=C2=A0using=C2=A0the=C2=A0hook,=C2=A0it=C2=A0became=C2= =A0the=C2=A0issue=C2=A0you=C2=A0discovered.=0D=0A>>>=0D=0A>>>=C2=A0The=C2= =A0reason=C2=A0that=C2=A0we=C2=A0have=C2=A0all=C2=A0this=C2=A0confusion=C2= =A0is=C2=A0that=C2=A0SELinux=0D=0A>>>=C2=A0generates=C2=A0security=C2=A0con= texts=C2=A0as=C2=A0needed,=C2=A0while=C2=A0Smack=C2=A0keeps=C2=A0them=0D=0A= >>>=C2=A0around=C2=A0all=C2=A0the=C2=A0time.=C2=A0Releasing=C2=A0an=C2=A0SE= Linux=C2=A0context=C2=A0frees=C2=A0memory,=0D=0A>>>=C2=A0while=C2=A0releasi= ng=C2=A0a=C2=A0Smack=C2=A0context=C2=A0is=C2=A0a=C2=A0null=C2=A0operation.= =0D=0A>>=C2=A0Any=C2=A0chance=C2=A0this=C2=A0detail=C2=A0can=C2=A0be=C2=A0h= idden=C2=A0behind=C2=A0security=C2=A0api?=C2=A0=C2=A0This=C2=A0looks=0D=0A>= >=C2=A0pretty=C2=A0error-prone,=C2=A0no?=0D=0A=C2=A0=0D=0A>>It=C2=A0*is*=C2= =A0hidden=C2=A0behind=C2=A0the=C2=A0security=C2=A0API.=C2=A0The=C2=A0proble= m=C2=A0is=C2=A0strictly=0D=0A>>within=C2=A0the=C2=A0Smack=C2=A0code,=C2=A0w= here=C2=A0the=C2=A0implementer=C2=A0of=C2=A0smack_inode_getsecctx()=0D=0A>>= made=C2=A0an=C2=A0error.=0D=0A=0D=0AI=20agree=20that=20the=20fix=20can=20be= =20done=20simply=20by=20using=20=22false=22=20for=20=0D=0Asmack_inode_getse= curity(),=20but=20what=20happens=20with=20kernfs_node_setsecdata()=0D=0Aand= =20smack_inode_notifysecctx().=20kernfs_node_setsecdata()=20is=20probably= =20ignorable=0D=0Abut=20smack_inode_notifysecctx()=20is=20sending=20the=20= =22ctx=22=20to=20smack_inode_setsecurity()=0D=0Aand=20since=20=22ctx=22=20w= ould=20be=20NULL=20because=20we=20used=20=22false=22,=20smack_inode_setsecu= rity()=0D=0Abecomes=20dummy.=0D=0A=0D=0A