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: 47667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2093145wrn; Tue, 24 Jan 2023 03:25:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXui+q8XYszUXNvveOBKKI6hodqJ8535/z2LsgMHbhIZOn3Qpf7DwW2pMTL/oKWXv/UeGyJy X-Received: by 2002:a17:907:8c14:b0:84c:e9c4:5751 with SMTP id ta20-20020a1709078c1400b0084ce9c45751mr30076985ejc.74.1674559506007; Tue, 24 Jan 2023 03:25:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674559505; cv=none; d=google.com; s=arc-20160816; b=WBAwnzZW4hflvsmzJXq4UKlOxJMr2s35SsCKrYdWAC+/RSvkeBk6DUrALAFTT1djbl twu+1mN9E16ffEYYfcKiYayhuct4GR/EXZAhCa/3yZYLhWHQl862BXrRbWVCRSwY2+oM lUM7UGMLptgiO7l3AiBY9d6V6XtuRueiVzvqvqc2f6xggpSCJFsRZJQELcuBgcEVUnUa /hYzILQ6X/8iqbkr7jslN1oORZdrPbc4Nvk59nkBgDf64kERFvdW7m8BRwb9WZbPdYTI n4T6Y77NBprTAEzcndCv1ccdYbNRfCuqkX6r5MRe7JWpl16hSqhfROW8OmXhonPRGQQw WGcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=aD4/h9d4fdnCay6mck+bYpcLc26YjKd4Wc2Mq5yvcbU=; b=B6QDHuZ37cJBQCpFA34hU+tPiYhyFfySaIgRkFRTjG5LfzYhgee0RTFZSveMT3TP7Z bum27Cq7GKOJJkXG/uPuJ2Y3nIatu3jRy5UFOM9gqTD1G3+4rlSggFOBl5I8jgKh9g2r u9rww96oBzWkllLoSGkOOcZsjqMG2aa5G+h3AC3jlf06kr7lpddC393CXDlKw8wWUV19 utJHX1XfsOVMoquDMgXPOJRgQK8FD9D9gOuPVU3qnXF8xx+Xbs+poXgzBbGaZQC6BpuH +xUhMrgPn8bSkwTGB91f5F968t7YJULTt63uf7tAzpJd43zKlkgtxATWygO2dDg87e3+ pcCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=kAotjoS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fv38-20020a17090750a600b007c18e1ecaf5si1978582ejc.654.2023.01.24.03.24.42; Tue, 24 Jan 2023 03:25:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=kAotjoS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233906AbjAXLP7 (ORCPT + 99 others); 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755902909010113626?= X-GMAIL-MSGID: =?utf-8?q?1755902909010113626?= 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;