Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2933244iog; Mon, 20 Jun 2022 07:46:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1t3WMnReh/gqrIwXOZ5Dvb6ZZJ6cdLKCdBzBy9PvWZZT+XW7/CE5xxU6oySMUXMYasn2n X-Received: by 2002:a17:90a:66c1:b0:1e8:43ae:f7c0 with SMTP id z1-20020a17090a66c100b001e843aef7c0mr27513170pjl.245.1655736399169; Mon, 20 Jun 2022 07:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736399; cv=none; d=google.com; s=arc-20160816; b=gN+qXB1QCgbiLQ3AhaoFfnKaC+GZeOWjNe+bgIi9wqmblgVtBqxsTOOMEg/tUq/HON AhyJ8Y42OL94X30JHf/vzYTubk2mhmYl29vy8p16wEDUj974wHzAphWp6ZbSgor+PsGh rsLKxAVOXDcGTZ5hJZFeRys5QC+alvYkqi5i7TNTQRx2FBjP9NmREoViqZKQLIsP42NL OCDnA1LxtKqN9h3dRa0qaWfJCPS7j4g8ZN905xSG5rVpIhgn8R9St9AXJBURLywpDYpn v+6EFQth1zk2O67jQLK0Cft8J9npRVDduRG13NScBtZpReXm6CKYCR7TkIQCUH2cV2Xk xUvg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gq7OB3Q0HPM8RNmRgyLqfQns4Pva/1MceWc/f2EB8+s=; b=0pyE/AG8HqBT3vYZ83JWUzpfrEW5zz50i0OHhyfns7VLRQAts82X9dVejhk0Pk8LJs s6qqcEOqVngdgMcGVkSO2s+68kesnKsU20vJ8cE9dxuScxTbQzncdHGIyF0flJxh0n51 SRvyduxsvS7GhTackgHTEg+xSjcTJGOu6D/vPlIg85uKmdAwAxqLTBQb+LvHXdl9Mqy2 C4vecVqojTTt8nXlug0NO6Yd3ICjBVMIlP8VVrl9N+Zrxj7mTZ/HG0MWEm8QAW68YHUl CqfS1QcWEAyZW20qyFGjAJFJPM7QhxxmZL9hHymZj549JxtZJFugFbusYlui83li80ol WVjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KJPI9aJH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u34-20020a634722000000b0040c757c212dsi11761382pga.450.2022.06.20.07.46.27; Mon, 20 Jun 2022 07:46:39 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=KJPI9aJH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240557AbiFTNKg (ORCPT + 99 others); Mon, 20 Jun 2022 09:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244550AbiFTNFo (ORCPT ); Mon, 20 Jun 2022 09:05:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88C7C19F8B; Mon, 20 Jun 2022 06:00:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 38E7AB811C1; Mon, 20 Jun 2022 13:00:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A68C3411B; Mon, 20 Jun 2022 13:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730014; bh=EeDfFiTCi71k1MEHOyK+pfp0jw6HhaaTBU2SKACSyXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJPI9aJHzC1EbIQpsLaaRgST6L5QbxkuQJOz8Y4/QsgZWF9yTBfQqLOAHkxxdBxZT VwZMhDNZ+jS/ipOtNZjXKB3lHxMtFR/KdVrXRTXitwqSNRcaY3VkncKW1LseC0Ucg1 ULLExxFPmn2Ou4Cea3WepOv+3exNYniYtyoO/iUg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20G=C3=B6ttsche?= , Paul Moore Subject: [PATCH 5.18 126/141] selinux: free contexts previously transferred in selinux_add_opt() Date: Mon, 20 Jun 2022 14:51:04 +0200 Message-Id: <20220620124733.278609889@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124729.509745706@linuxfoundation.org> References: <20220620124729.509745706@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Christian Göttsche commit cad140d00899e7a9cb6fe93b282051df589e671c upstream. `selinux_add_opt()` stopped taking ownership of the passed context since commit 70f4169ab421 ("selinux: parse contexts for mount options early"). unreferenced object 0xffff888114dfd140 (size 64): comm "mount", pid 15182, jiffies 4295687028 (age 796.340s) hex dump (first 32 bytes): 73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f system_u:object_ 72 3a 74 65 73 74 5f 66 69 6c 65 73 79 73 74 65 r:test_filesyste backtrace: [] kmemdup_nul+0x24/0x80 [] selinux_sb_eat_lsm_opts+0x293/0x560 [] security_sb_eat_lsm_opts+0x58/0x80 [] generic_parse_monolithic+0x82/0x180 [] do_new_mount+0x1f5/0x550 [] path_mount+0x2ab/0x1570 [] __x64_sys_mount+0x20e/0x280 [] do_syscall_64+0x34/0x80 [] entry_SYSCALL_64_after_hwframe+0x46/0xb0 unreferenced object 0xffff888108e71640 (size 64): comm "fsmount", pid 7607, jiffies 4295044974 (age 1601.016s) hex dump (first 32 bytes): 73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f system_u:object_ 72 3a 74 65 73 74 5f 66 69 6c 65 73 79 73 74 65 r:test_filesyste backtrace: [] memdup_user+0x21/0x90 [] strndup_user+0x47/0xa0 [] __do_sys_fsconfig+0x485/0x9f0 [] do_syscall_64+0x34/0x80 [] entry_SYSCALL_64_after_hwframe+0x46/0xb0 Cc: stable@vger.kernel.org Fixes: 70f4169ab421 ("selinux: parse contexts for mount options early") Signed-off-by: Christian Göttsche Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2600,8 +2600,9 @@ static int selinux_sb_eat_lsm_opts(char } } rc = selinux_add_opt(token, arg, mnt_opts); + kfree(arg); + arg = NULL; if (unlikely(rc)) { - kfree(arg); goto free_opt; } } else { @@ -2792,17 +2793,13 @@ static int selinux_fs_context_parse_para struct fs_parameter *param) { struct fs_parse_result result; - int opt, rc; + int opt; opt = fs_parse(fc, selinux_fs_parameters, param, &result); if (opt < 0) return opt; - rc = selinux_add_opt(opt, param->string, &fc->security); - if (!rc) - param->string = NULL; - - return rc; + return selinux_add_opt(opt, param->string, &fc->security); } /* inode security operations */