From patchwork Tue May 29 13:11:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10435345 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 04216602CC for ; Tue, 29 May 2018 13:11:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6D0028745 for ; Tue, 29 May 2018 13:11:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB6952874F; Tue, 29 May 2018 13:11:54 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D39528745 for ; Tue, 29 May 2018 13:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934271AbeE2NLw (ORCPT ); Tue, 29 May 2018 09:11:52 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:33276 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934263AbeE2NLs (ORCPT ); Tue, 29 May 2018 09:11:48 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4TDAsRs063877; Tue, 29 May 2018 13:11:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=M4SumV5fT1+44mOLP5mvXRBNzlaaRSgyFdYVrJL1HwY=; b=UxMgHcDVSMlu5u2C34Cbpm6FI0MNHSmEEFx6pnAeZlDE9D3VygF+6dA8AaKH5Ehd/VDa 1Z8EgYTd4jhye7AAv5GcSjQfhZ5vAtdJR4SPRk72rbZzXN0l3GiVEtRiVfvoEoDyEIBz R7y9rCR1Yu6sEw2P5yPQ+SE0pKQsQ1qZx4Ldo4lcbeQ3c1m04kfwa0SW2RAHNsXLHpU0 kaok+ZTOZ/0kjVZ6AeJiuOgE3gfdUgdVvYdU50xzYRtrrqfGU6PtTn247PzGN88RwlPK tucEllEOvrvzQADs1//DHFI5u1Qsc7bskCETARMaKD+0XQDuFQMfS7gcdUC3ewSd2UKz Lg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2j6w42he3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 May 2018 13:11:41 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4TDBeoX029932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 May 2018 13:11:40 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4TDBdkG014862; Tue, 29 May 2018 13:11:39 GMT Received: from kili.mountain (/197.157.0.20) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 May 2018 06:11:38 -0700 Date: Tue, 29 May 2018 16:11:28 +0300 From: Dan Carpenter To: Mimi Zohar , Matthew Garrett Cc: James Morris , "Serge E. Hallyn" , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] EVM: prevent array underflow in evm_write_xattrs() Message-ID: <20180529131128.3rkzzv66uy6h5ts7@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1527597092.10176.17.camel@linux.vnet.ibm.com> X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8907 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=978 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805290151 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP If the user sets xattr->name[0] to NUL then we would read one character before the start of the array. This bug seems harmless as far as I can see but perhaps it would trigger a warning in KASAN. Fixes: fa516b66a1bf ("EVM: Allow runtime modification of the set of verified xattrs") Signed-off-by: Dan Carpenter --- The user can pass a zeroed buffer to memdup_user_nul() so we can't rely on "count" to test this. -- 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 diff --git a/security/integrity/evm/evm_secfs.c b/security/integrity/evm/evm_secfs.c index a7a0a1acae99..94c739180a0b 100644 --- a/security/integrity/evm/evm_secfs.c +++ b/security/integrity/evm/evm_secfs.c @@ -207,7 +207,7 @@ static ssize_t evm_write_xattrs(struct file *file, const char __user *buf, /* Remove any trailing newline */ len = strlen(xattr->name); - if (xattr->name[len-1] == '\n') + if (len && xattr->name[len-1] == '\n') xattr->name[len-1] = '\0'; if (strcmp(xattr->name, ".") == 0) {