From patchwork Fri Jul 2 20:28:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khem Raj X-Patchwork-Id: 44130 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 739D83886C79 for ; Fri, 2 Jul 2021 20:28:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 739D83886C79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625257717; bh=BskLJoXAekDI/gaiFrzAV20weMUHgNwVnUGdnu300Qg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=q9LOJnvnDdPAP07OY9ZAJ/k/vEx2f1TDc3bQ75rxpfPhrI0E9zKQeSlIwd743ykaK pvQdEjEBLD5AygzPOBdvuAee5AySgqyeuRgO3fwTcLZgpKSaWVR0cEyFBh3wUd+5rN HbXO/jnH4m5B4ygT31GKvwOA1gvo3X9i5AIVmZic= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id BD00C385BF9B for ; Fri, 2 Jul 2021 20:28:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD00C385BF9B Received: by mail-pj1-x1030.google.com with SMTP id b8-20020a17090a4888b02901725eedd346so3969020pjh.4 for ; Fri, 02 Jul 2021 13:28:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BskLJoXAekDI/gaiFrzAV20weMUHgNwVnUGdnu300Qg=; b=aPqYbk8L+RNp26pcrpF+LGMzyBHrJ9YworTFkUwc3Q6OGOfUNU+uXW4ANxTJgchEXU PEPDQXO5qlLzC7x77wU+3eVV7XQW1F8iLTze57bs8Op59CXoLd7ULombeJLVGp5lqe3f FmbxJXaIVDYtZJQkRfooAgjgrd5cd6Fr8VJWtyx/hNigdwOvCAGehOPtMTgnf38P7GUr kJUa2Az2MRxjz94M2gUDjMZiEr5y7HktE4rIGbtHrPEyZA/Wj4lNLTHE9DKH5f1g2Utu YugLb6wETIuSa5ZebfRHoRxjl37yjUt2snP2TAQxf0WbqMqTIcTIzzwjOWe5941I6MqY wYVQ== X-Gm-Message-State: AOAM533YhlA0+dxAUmNoZN5Tl5YzvZ//Z3I4yez/BUKnKXhQtywjVI9g dZo1OeaSbqpz9+SVbeFWbMFujI3ZTSGRdw== X-Google-Smtp-Source: ABdhPJxVTyfgtiUgB0PhI7gCKrKYel1cxVyFLw2OV4mrhfWocp+34M8lyVm9Vmy9zquaUlwQwpLEFQ== X-Received: by 2002:a17:90a:3b84:: with SMTP id e4mr1369933pjc.25.1625257693632; Fri, 02 Jul 2021 13:28:13 -0700 (PDT) Received: from apollo.hsd1.ca.comcast.net ([2601:646:9200:a0f0::1c2d]) by smtp.gmail.com with ESMTPSA id p29sm4385759pfq.55.2021.07.02.13.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 13:28:13 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Check for null value msghdr struct before use Date: Fri, 2 Jul 2021 13:28:10 -0700 Message-Id: <20210702202810.2779765-1-raj.khem@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Khem Raj via Libc-alpha From: Khem Raj Reply-To: Khem Raj Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This avoids crashes in libc when cmsg is null and refrencing msg structure when it is null Signed-off-by: Khem Raj Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/convert_scm_timestamps.c | 2 ++ sysdeps/unix/sysv/linux/recvmsg.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c index d75a4618dd6..5af71847f57 100644 --- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c +++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c @@ -87,6 +87,8 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) msg->msg_controllen += CMSG_SPACE (sizeof tvts); cmsg = CMSG_NXTHDR(msg, last); + if (cmsg == NULL) + return; cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = type; cmsg->cmsg_len = CMSG_LEN (sizeof tvts); diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c index a2a600228ba..19c49e2a85c 100644 --- a/sysdeps/unix/sysv/linux/recvmsg.c +++ b/sysdeps/unix/sysv/linux/recvmsg.c @@ -25,7 +25,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags) { ssize_t r; #ifndef __ASSUME_TIME64_SYSCALLS - socklen_t orig_controllen = msg->msg_controllen; + socklen_t orig_controllen = (msg) ? msg->msg_controllen : 0; #endif #ifdef __ASSUME_RECVMSG_SYSCALL @@ -35,7 +35,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags) #endif #ifndef __ASSUME_TIME64_SYSCALLS - if (r >= 0) + if (r >= 0 && orig_controllen) __convert_scm_timestamps (msg, orig_controllen); #endif