Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp700405pxb; Tue, 5 Apr 2022 19:20:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqfuE6vmLTHdKGdVVJX39FVFmaYnaahndKHK5UrOs5DbrYsAS7rKF+EwumrPTjXFI+/hhu X-Received: by 2002:a17:902:d48c:b0:156:956e:4588 with SMTP id c12-20020a170902d48c00b00156956e4588mr6167531plg.105.1649211561941; Tue, 05 Apr 2022 19:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649211561; cv=none; d=google.com; s=arc-20160816; b=YrOnTkR28IpBkQ8TCjMDdDUWEmNFeB1wYctB3KrEC1g7A4jbrKKV67956AN9AcuA3t hv3tr/9ssv7XnUBIyUUVUurdxKdTrb1IFv+uNkw8k1zu0RqEOVBSei3BJHLOLxBRMSef aaXHuItXC6GjCSm8DTRgObxO1G+tCxvRTffthfIe9U2nbonVs4DyHzgpXLpazDMQm7Gd J3KuYwmhim4KFQK+qkeX0KN/6qBfOns+eXv2FZA0OCHyELJVzfQrNvWBMyG5fQiuuDeu kuEqan7C3I49UX2clkVfAfav0I+V+6Y9SZkpQHYXpxlEEyTab1277vDb9yjpoeMWZn7B KJLA== 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=PcksWkNFeOUQlAisQUtsoLmAL1XP6cC2QACSNJmqURc=; b=0kbir4BzwQKnHKnwDJoAlV2ypd0CQXBN4IVhfBeddMOeQCh/8GLg95D7MEwcCFnEHT w8WXTOoWEmKFLVnt2KdE79bv+0mYOagJIvoo7zl7SNnydGknrzLhWEkkdj9fgWw+VaHk vmwgIMMNzJfClxJnybvt2kCdlv5ff14nbYqAz92Knzk2yW3oc0Ajt8ncF34sAP0xomCB 6DTP9vhmTgU6B0MVjuTkNEYvgEfDM37Jz6d/auPaW9bwa2B42HkKSsLauwEYTfXZSMeO urP8fS1cBmvtoK/ZPSNRPjtoBi0GXLaO0XFAVLp5hiSPKZqvPzpQa+dZt6rcVkhBOkZs y96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="dS//EjcI"; 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 na4-20020a17090b4c0400b001bf80eb1bcdsi3909943pjb.120.2022.04.05.19.19.06; Tue, 05 Apr 2022 19:19:21 -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="dS//EjcI"; 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 S1353379AbiDEMto (ORCPT + 99 others); Tue, 5 Apr 2022 08:49:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244259AbiDEJJv (ORCPT ); Tue, 5 Apr 2022 05:09:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE5A7205EC; Tue, 5 Apr 2022 01:59:13 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7FCF16159F; Tue, 5 Apr 2022 08:59:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DC53C385A3; Tue, 5 Apr 2022 08:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149149; bh=68tEdpLmNp8IW56JqoG0OPYoak/d+7TDd4489L5IY4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dS//EjcIwWb2cdYLKF7AzuuMboCnqtQALcuCzcGQ8VrSc0EZHOV7RIu8svBrD9U2M LFKBOeU2bGbX+Tx0JUI9vOpFxmlRX3lt0pKTG8WV2jXaQibJxU8FhILIiD/C6KYuT7 Zf+KSWA9+FBbTqke0l7B+LsivkOjWR/yfvedxWOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Derek Will , Oliver Hartkopp , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.16 0612/1017] can: isotp: support MSG_TRUNC flag when reading from socket Date: Tue, 5 Apr 2022 09:25:25 +0200 Message-Id: <20220405070412.448960205@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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.1 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: Oliver Hartkopp [ Upstream commit 42bf50a1795a1854d48717b7361dbdbce496b16b ] When providing the MSG_TRUNC flag via recvmsg() syscall the return value provides the real length of the packet or datagram, even when it was longer than the passed buffer. Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol") Link: https://github.com/linux-can/can-utils/issues/347#issuecomment-1065932671 Link: https://lore.kernel.org/all/20220316164258.54155-3-socketcan@hartkopp.net Suggested-by: Derek Will Signed-off-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/isotp.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/net/can/isotp.c b/net/can/isotp.c index 8966f06e0660..ad61342d2e16 100644 --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -1006,29 +1006,28 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, struct sock *sk = sock->sk; struct sk_buff *skb; struct isotp_sock *so = isotp_sk(sk); - int err = 0; - int noblock; + int noblock = flags & MSG_DONTWAIT; + int ret = 0; - noblock = flags & MSG_DONTWAIT; - flags &= ~MSG_DONTWAIT; + if (flags & ~(MSG_DONTWAIT | MSG_TRUNC)) + return -EINVAL; if (!so->bound) return -EADDRNOTAVAIL; - skb = skb_recv_datagram(sk, flags, noblock, &err); + flags &= ~MSG_DONTWAIT; + skb = skb_recv_datagram(sk, flags, noblock, &ret); if (!skb) - return err; + return ret; if (size < skb->len) msg->msg_flags |= MSG_TRUNC; else size = skb->len; - err = memcpy_to_msg(msg, skb->data, size); - if (err < 0) { - skb_free_datagram(sk, skb); - return err; - } + ret = memcpy_to_msg(msg, skb->data, size); + if (ret < 0) + goto out_err; sock_recv_timestamp(msg, sk, skb); @@ -1038,9 +1037,13 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, memcpy(msg->msg_name, skb->cb, msg->msg_namelen); } + /* set length of return value */ + ret = (flags & MSG_TRUNC) ? skb->len : size; + +out_err: skb_free_datagram(sk, skb); - return size; + return ret; } static int isotp_release(struct socket *sock) -- 2.34.1