From patchwork Tue Jan 24 10:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Arefev X-Patchwork-Id: 13113832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5EDFC25B4E for ; Tue, 24 Jan 2023 11:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbjAXLP7 (ORCPT ); Tue, 24 Jan 2023 06:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233915AbjAXLPz (ORCPT ); Tue, 24 Jan 2023 06:15:55 -0500 X-Greylist: delayed 901 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 24 Jan 2023 03:15:48 PST Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E21813E63F; Tue, 24 Jan 2023 03:15:47 -0800 (PST) From: Denis Arefev DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1674557437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=aD4/h9d4fdnCay6mck+bYpcLc26YjKd4Wc2Mq5yvcbU=; b=kAotjoS+d+k9Lh4ogAm7MW/ZgGTPfW79NNEjl8gEv4rnxU/Xb1Tddt+3YMXPUpPLwKXfkp VIA3w+ahpW5+XvvAn9oBzTGPzL1W85NiQ2RV3HqLVZQ9dr4Tj3Wbs0hV29GgzJPafPdfkS +JftDJcFoxCQE3Duax3BwNwr1Wvfpoo= To: Casey Schaufler Cc: Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, trufanov@swemel.ru, vfh@swemel.ru Subject: [PATCH] smackfs: Added check catlen Date: Tue, 24 Jan 2023 13:50:37 +0300 Message-Id: <20230124105037.23108-1-arefev@swemel.ru> MIME-Version: 1.0 Precedence: bulk List-ID: If the catlen is 0, the memory for the netlbl_lsm_catmap structure must be allocated anyway, otherwise the check of such rules is not completed correctly. Signed-off-by: Denis Arefev --- security/smack/smackfs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 4b58526450d4..d45f4395a6ce 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -830,7 +830,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file) static ssize_t smk_set_cipso(struct file *file, const char __user *buf, size_t count, loff_t *ppos, int format) { - struct netlbl_lsm_catmap *old_cat; + struct netlbl_lsm_catmap *old_cat, *new_cat = NULL; struct smack_known *skp; struct netlbl_lsm_secattr ncats; char mapcatset[SMK_CIPSOLEN]; @@ -917,8 +917,19 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf, smack_catset_bit(cat, mapcatset); } - - rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN); + ncats.flags = 0; + if (catlen == 0) { + ncats.attr.mls.cat = NULL; + ncats.attr.mls.lvl = maplevel; + new_cat = netlbl_catmap_alloc(GFP_ATOMIC); + if (new_cat) + new_cat->next = ncats.attr.mls.cat; + ncats.attr.mls.cat = new_cat; + skp->smk_netlabel.flags &= ~(1U << 3); + rc = 0; + } else { + rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN); + } if (rc >= 0) { old_cat = skp->smk_netlabel.attr.mls.cat; skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;