Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3331428imm; Tue, 29 May 2018 05:31:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqI3//xtR7Uo/3BP0w14cY+hia1/j5XAbkZD2bNfVDjw8tFu/YWMMNd1ZvcPvIt0kT5UGd/ X-Received: by 2002:a17:902:9883:: with SMTP id s3-v6mr17631646plp.179.1527597114633; Tue, 29 May 2018 05:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527597114; cv=none; d=google.com; s=arc-20160816; b=0hsRmxNSMNZTPs3cf0JHqrglhMt9K1NsqqXgCsiE1+ptHMzHnSBrSAwVdxKsinQGGt S1opes79/9NeF5udxWN5fQn7GQWTtXc0SfY3tYytctUn4uLK/o9Ok+Z1EzTXRVET90pV EqidWyF9GofGreRQbVZCVotvf4NsDEDXgWFrmyWIPoWu3iCnlB5iDNEgmXRxfzNrOtiA X81rUy92VpG4ba350/YobeJ0Wajpzzis3+CeFGWl6/r29Ehj1LnyHweY0YRWBzmRSp7c mu3ps+mr1NFZlsasS3tGp/uoZn/Jq5aSHBXinRfsNDPNWOksXFRNGqYUfGGDosrYxLef asuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=8N5viUIbIzNJRuVIGXNSFes9YnmNATVqskIPYksyA/k=; b=FPnfZFdjt3Bm/40HdxsMQzAXeimwU0md8ZyLSI4Jx26vhiDQtgCUjq/tsMiV1ej7zI CAK28i+b+dONlisp9jja/4llHSwpyJhbaOGgYp/ksaTn23VRhR+PzMR3qsTr87qkahg5 m4dNYlJnH5rA37i1vJgMdnjvgw8t2VL+BbCLW2hhwQwXx1+s1XitJZXi0W3SnqLKVQWs cJE1apLzt4CoUwwtTqLoXuPVLwVNTreCPFPV8iOjVb3dqHMP5Qzcf2SmIc+BfG5kWdY0 kgQ2wQSZ80lSFXVWb3wCSplP51pJhw0X0hXVj51vmkgmNDTLpqxCumTfw/Athk1ElBQ0 k7bA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si33369144plg.260.2018.05.29.05.31.40; Tue, 29 May 2018 05:31:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933872AbeE2Max (ORCPT + 99 others); Tue, 29 May 2018 08:30:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41006 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933732AbeE2Mat (ORCPT ); Tue, 29 May 2018 08:30:49 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TCTxcj043526 for ; Tue, 29 May 2018 08:30:49 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j94swwybb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 08:30:48 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:30:43 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:30:40 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TCUdGW22675604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:30:39 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAEBCAE053; Tue, 29 May 2018 13:19:46 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3FCEAE045; Tue, 29 May 2018 13:19:45 +0100 (BST) Received: from localhost.localdomain (unknown [9.80.109.170]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 29 May 2018 13:19:45 +0100 (BST) Subject: Re: [PATCH] EVM: Fix null dereference on xattr when xattr fails to allocate From: Mimi Zohar To: Colin King , Matthew Garrett , James Morris , "Serge E . Hallyn" , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 29 May 2018 08:30:27 -0400 In-Reply-To: <20180527225510.25612-1-colin.king@canonical.com> References: <20180527225510.25612-1-colin.king@canonical.com> 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-GCONF: 00 x-cbid: 18052912-0044-0000-0000-00000557F62A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052912-0045-0000-0000-0000289A042E Message-Id: <1527597027.10176.16.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-29_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805290143 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Colin, On Sun, 2018-05-27 at 23:55 +0100, Colin King wrote: > From: Colin Ian King > > In the case where the allocation of xattr fails and xattr is NULL, the > error exit return path via label 'out' will dereference xattr when > kfree'ing xattr-name. Fix this by only kfree'ing xattr->name and xattr > when xattr is non-null. > > Detected by CoverityScan, CID#1469366 ("Dereference after null check") > > Fixes: fa516b66a1bf ("EVM: Allow runtime modification of the set of verified xattrs") > Signed-off-by: Colin Ian King > --- > security/integrity/evm/evm_secfs.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/security/integrity/evm/evm_secfs.c b/security/integrity/evm/evm_secfs.c > index fb8bc950aceb..cf5cd303d7c0 100644 > --- a/security/integrity/evm/evm_secfs.c > +++ b/security/integrity/evm/evm_secfs.c > @@ -253,8 +253,10 @@ static ssize_t evm_write_xattrs(struct file *file, const char __user *buf, > out: > audit_log_format(ab, " res=%d", err); > audit_log_end(ab); > - kfree(xattr->name); > - kfree(xattr); > + if (xattr) { > + kfree(xattr->name); > + kfree(xattr); > + } > return err; > } > Thanks!  To fix this problem, I think more is needed. Without the xattr, there is nothing to audit except the attempt to extend the xattr list.  Failure to allocate the xattr or xattr->name should either result in a different audit message or return immediately without any audit message. Mimi