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 83521C6FD1C for ; Mon, 13 Mar 2023 11:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbjCMLdx (ORCPT ); Mon, 13 Mar 2023 07:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbjCMLdk (ORCPT ); Mon, 13 Mar 2023 07:33:40 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDB59EEE for ; Mon, 13 Mar 2023 04:33:09 -0700 (PDT) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 632A13F17A for ; Mon, 13 Mar 2023 11:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678707155; bh=WIlBGmglyBuO5BTm3a9yo13ImKUTaHbAmYajOjqNXTU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=YFyJNP0k8kE4iQLY3jBeDeIKKjYkkFg9Fh0e00Lq/Hv1VuADjZrxGm7NubzU73mHm drNaS5tZkfGnnb9noxWMBk6hGvl1wXReZhLyOYveZgKvet9bIQR0oq4v5cRLbRYEen HbDo0g41m+3dHnKEsPCZmP+qTcmIwxxaGMKwjIa8b7TSqG0p/pOCg4uU393CK53KKP NwnHdHNKk6ABjwr3dqw63U8HEum3zjquWwA2smShv5Fbkti1xtkS63nhz3XgC1Sb2v zGukGgjvxnwicoaYRmqSPBdszTO7hrHBmJ5rjbUt0q8UTu0kPR6KSfkUf8gY4BnrwK j4QTZ1XwSXGiA== Received: by mail-ed1-f69.google.com with SMTP id q13-20020a5085cd000000b004af50de0bcfso16736447edh.15 for ; Mon, 13 Mar 2023 04:32:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707155; 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=WIlBGmglyBuO5BTm3a9yo13ImKUTaHbAmYajOjqNXTU=; b=rQAfP+SZr6pW7WufbYUoKnTKsZ+MLfHBo3f7Gra36/WZ/aCUFuHAGVhy8td5Qh0mht CyZWTAk6t7rVc8XUykY0mqO0yheQqzUWaJgmAoKQvy4okyfutzC4qi05vKGXBebFR0Tg pTychnBbG6HTEF7ZeTLLC/CHszo1sKRGAvnc5dxKuG95pErUwduNuCwuOxskMSlYM31+ I9KN6a96svubeOZ8QFf8HL4MRyZgmhpjZYCk2AnhF+CZvnjDNP9OaG6WcbfGZQuj/AR6 MVy57ST3bLe7ECX+cSh0FASuLI9/cLQoB0wJxfIsyIFgUdsACxb5WfWxozyUWOsOtIWF rPJQ== X-Gm-Message-State: AO0yUKWD0t4IpoGCyfkBx27vDHWVokBwz61OSB0cqm21j/vEwZIr97Wy efdj7nB/D+kfffvw2v9Ce5xA8IJpbSTZreZRBxCFe5x55ZC64AZue1L5gROqaWYLDxyKUHfWK0l 2j8mSwqyqx8+VXcV1E9ZtMf6mlctYtDfu4+6NidmloQ== X-Received: by 2002:a17:907:80e:b0:8b0:f58d:2da9 with SMTP id wv14-20020a170907080e00b008b0f58d2da9mr43616157ejb.64.1678707155167; Mon, 13 Mar 2023 04:32:35 -0700 (PDT) X-Google-Smtp-Source: AK7set9QXQ820wthA8mkfj06/eCxY8qoFLG6I5ahUEUqt7xmAJQ/WsddvBW3t4NjAyTyI8jC9qOEsQ== X-Received: by 2002:a17:907:80e:b0:8b0:f58d:2da9 with SMTP id wv14-20020a170907080e00b008b0f58d2da9mr43616132ejb.64.1678707154858; Mon, 13 Mar 2023 04:32:34 -0700 (PDT) Received: from amikhalitsyn.. ([2a02:8109:bd40:1414:c91d:59c1:64e:937b]) by smtp.gmail.com with ESMTPSA id r8-20020a50d688000000b004fbf6b35a56sm1351501edi.76.2023.03.13.04.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:32:34 -0700 (PDT) From: Alexander Mikhalitsyn To: davem@davemloft.net Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Alexander Mikhalitsyn , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Leon Romanovsky Subject: [PATCH net-next v2] scm: fix MSG_CTRUNC setting condition for SO_PASSSEC Date: Mon, 13 Mar 2023 12:32:11 +0100 Message-Id: <20230313113211.178010-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, kernel would set MSG_CTRUNC flag if msg_control buffer wasn't provided and SO_PASSCRED was set or if there was pending SCM_RIGHTS. For some reason we have no corresponding check for SO_PASSSEC. In the recvmsg(2) doc we have: MSG_CTRUNC indicates that some control data was discarded due to lack of space in the buffer for ancillary data. So, we need to set MSG_CTRUNC flag for all types of SCM. This change can break applications those don't check MSG_CTRUNC flag. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Leon Romanovsky Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Alexander Mikhalitsyn v2: - commit message was rewritten according to Eric's suggestion --- include/net/scm.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/net/scm.h b/include/net/scm.h index 1ce365f4c256..585adc1346bd 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -105,16 +105,27 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc } } } + +static inline bool scm_has_secdata(struct socket *sock) +{ + return test_bit(SOCK_PASSSEC, &sock->flags); +} #else static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm) { } + +static inline bool scm_has_secdata(struct socket *sock) +{ + return false; +} #endif /* CONFIG_SECURITY_NETWORK */ static __inline__ void scm_recv(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm, int flags) { if (!msg->msg_control) { - if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp) + if (test_bit(SOCK_PASSCRED, &sock->flags) || scm->fp || + scm_has_secdata(sock)) msg->msg_flags |= MSG_CTRUNC; scm_destroy(scm); return; -- 2.34.1