From patchwork Thu May 11 12:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 92553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4339450vqo; Thu, 11 May 2023 05:43:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Z74vUAdYvD16la4fxIz5/cIw1jgAC5igYQxCI2+qGcPWY/e0CB1fXkpSFEJ210OP60trW X-Received: by 2002:a05:6a00:2401:b0:63d:3339:e967 with SMTP id z1-20020a056a00240100b0063d3339e967mr26916942pfh.19.1683809016647; Thu, 11 May 2023 05:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683809016; cv=none; d=google.com; s=arc-20160816; b=YkMlLyX997Nt6vdLMZ3g1tpEo3Oeku861+X05TqNCB2zLNhecnKnzA3aloIl1YFIpV +/D5g4BKEo6hgWyC9+4X0illsBpKu0xKT8eWFAeH4BTCoGhd3FCxNUVG2S8Wvd/pRJYI 2eIdf6g8jybASC2bGpPVymw/emSdn45SKSsho7u+9y7UMlZOCr6G5snihDou4kU51HIq IdsLp1LTwsSZ8+dL4A8chh7VjGJxMCwe2TIOWcovoys8jli6Bpvv9yCyeIFU4SPXioCa +YEPv1SRkG6NaEHEDverfMEIW46VVuOq7N/a3vtGL7vWfOTMkIYLeE6ScLE/+PqcYEi3 YPvg== 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:from:dkim-signature; bh=1Uu5ruPXtdkWJNm3pGozn9KwxFsClD+TD7ca8ZM3nX8=; b=KNLaVremzJDs+gm1JmH7zrPvD3haQUPwW+PZP3nePby4IP2T40bdEZ5+Pk5RVsh86f DHhA7pcEH3Tjlm8bOunybQfjv4BbzegShybYoQSQQrR9XekG9UR5pyd7MRqhDyxv4iZD 6T7q+JBWO2xssdrcIURlZM517O2PA9N+/IBxEEP6WQx+Fy7FdJV/RL78uzsiKq+5oHUG 9tIgx5wbbkTg673epVI/E9qe5HEXVPejraSX2LvmFZ5R9VwGtaQyDTIS52rE8XiHw4Yu Mtwl9owqY7DmO1jlcvbcgruHGIDsTpVfOUXXhJAGr4fGjHDLNRtE/WUsssgXfKMYZ8Ja JKeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=c1rX78gO; 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=googlemail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i128-20020a625486000000b00647e5f1d563si4775091pfb.387.2023.05.11.05.43.21; Thu, 11 May 2023 05:43:36 -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=@googlemail.com header.s=20221208 header.b=c1rX78gO; 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=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237948AbjEKMcF (ORCPT + 99 others); Thu, 11 May 2023 08:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237327AbjEKMcE (ORCPT ); Thu, 11 May 2023 08:32:04 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192973C39; Thu, 11 May 2023 05:32:02 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-9659e9bbff5so1559402766b.1; Thu, 11 May 2023 05:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683808320; x=1686400320; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1Uu5ruPXtdkWJNm3pGozn9KwxFsClD+TD7ca8ZM3nX8=; b=c1rX78gOZvD1P9gtxXqsDNlehTS5/8+DamhUELsnNLUBsEGR9IkcilNrWgO5kWlYjk Qi3hQ9Jo1bEuVWJx2NlNXFaCDFdl7lARcAMJl8UyJCA9+ITcEKnXxs5NdQ71wiQTALQH GLW153SdrHnTs9vC6rvts+/tlufwdLvhWo/n2+4kPxKUVDdhrd8JGQzadWadrzcztVBn I2i8vCQDoqZ8Ehry1PxmyNxJuiLUofesP8lxJxv/lVsb7i6X1wbGk3p3aB2oI5W8zsTO Snx7RrhreYN6b/2WH6pbi+UqK68il8VKQCBpYlN20kL1z35Uz9VO/Q/RQetDGU3/GkS2 SDKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683808320; x=1686400320; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1Uu5ruPXtdkWJNm3pGozn9KwxFsClD+TD7ca8ZM3nX8=; b=ShznfxdvsPA6TjmB2SHrgb5ogLTkc4d6WomZhHbOdx5xQKquOcYx5DWgqNKdpYDZaV 9B2Jash8sGcS8FBklKEXB5VzIZZUb5womJddxKPwv2M4ybpZN+W0QuY24YP3PmaBRHt8 IAh5MmAH//GugaidEsoMoxU8FAZvzotwe5MADoNpCjqlgu2kmabc3I3DJdPcKUxS6BwO SygQXcUM/D+8OdsALqTXzukFul6kY/2R9gMQdbZnwS/JKN8TRlayw4ylfET4aS238ChL /2IgMQwaZuK8eveOFKIu6TY15ZtmFiO+HMjWjXukUatV2Mx6g0Ti6yK8lFUGZlRUF1sk Cb0g== X-Gm-Message-State: AC+VfDxtmi0oqVUXRRsRCpsXfsKi+7ENBUndlKeDjm98s5MBUZd1oBNN vM2df9wyLLu3VlrORvit6V/pcDjksAY= X-Received: by 2002:a17:906:4fd1:b0:96a:57fe:3bfb with SMTP id i17-20020a1709064fd100b0096a57fe3bfbmr2346619ejw.26.1683808320278; Thu, 11 May 2023 05:32:00 -0700 (PDT) Received: from debianHome.localdomain (dynamic-077-008-180-228.77.8.pool.telefonica.de. [77.8.180.228]) by smtp.gmail.com with ESMTPSA id h8-20020a1709060f4800b009600ce4fb53sm3906639ejj.37.2023.05.11.05.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 05:31:59 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , linux-kernel@vger.kernel.org Subject: [PATCH] selinux: keep context struct members in sync Date: Thu, 11 May 2023 14:31:47 +0200 Message-Id: <20230511123148.722343-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765601723573813029?= X-GMAIL-MSGID: =?utf-8?q?1765601723573813029?= Commit 53f3517ae087 ("selinux: do not leave dangling pointer behind") reset the `str` field of the `context` struct in an OOM error branch. In this struct the fields `str` and `len` are coupled and should be kept in sync. Set the length to zero according to the string be set to NULL. Fixes: 53f3517ae087 ("selinux: do not leave dangling pointer behind") Signed-off-by: Christian Göttsche --- security/selinux/ss/context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/security/selinux/ss/context.h b/security/selinux/ss/context.h index 44179977f434..aed704b8c642 100644 --- a/security/selinux/ss/context.h +++ b/security/selinux/ss/context.h @@ -168,6 +168,7 @@ static inline int context_cpy(struct context *dst, const struct context *src) if (rc) { kfree(dst->str); dst->str = NULL; + dst->len = 0; return rc; } return 0;