From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 2F0F5385503D for ; Mon, 5 Jul 2021 17:51:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F0F5385503D Received: by mail-pf1-x430.google.com with SMTP id q10so1047888pfj.12 for ; Mon, 05 Jul 2021 10:51:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=scqo0L5QGRNUfWkycemksksw0z7cjR7q7oyRSGCyt54=; b=GwzXysXQY4SWyIX+Xt0q7Zg07EyHDry02VKlYd39jnIcQGQjvLRn0S+cjJDtZKjwJM c3uZoOb0iNfJ/ADhbKiAZ71RsTWspgn7hjB1hyn/xgcI00eqdR3qcVgl2QvTlnmIhaWj SV3zb46W0wdjLK6Q+zXtB12De8NTeVVAloBVBmY5AmxHcZvaFkhMN4JAF65Porg5cebD GCrR8BLGbRqRh9q1Vs3+L10CROR3KeA07sCk6NoFUODHl80aa4P1jpYB+0Yd0rQU07RM xQp5o/9xEvgcHd5w/meLxSwHE3OJ24uuGbe22vvjbH5kAHbKWVCGDGpws0DPGTI7vnI5 tGrg== X-Gm-Message-State: AOAM531y9rCZyth6NoVB9KH4plbvCzo12bcQir37kc1lfF6/h6W/dILU x3o4bDiqhROGn/Qg5F2VfpdTRClZ6LzkZQ== X-Google-Smtp-Source: ABdhPJw1hl8Qqh+M2BPn7Pf7WExIFBkeTz0Tkqq6JIjHHS2hISdZ7Ol1tX2peMMUwytq0Ay9aK/eTw== X-Received: by 2002:a63:fa50:: with SMTP id g16mr17102601pgk.16.1625507487915; Mon, 05 Jul 2021 10:51:27 -0700 (PDT) Received: from [192.168.1.108] ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id c14sm3476681pfo.21.2021.07.05.10.51.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jul 2021 10:51:27 -0700 (PDT) Subject: Re: [PATCH] linux: Check for null value msghdr struct before use To: Khem Raj , libc-alpha@sourceware.org References: <20210702202810.2779765-1-raj.khem@gmail.com> From: Adhemerval Zanella Message-ID: Date: Mon, 5 Jul 2021 14:51:25 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210702202810.2779765-1-raj.khem@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, 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-List-Received-Date: Mon, 05 Jul 2021 17:51:34 -0000 On 02/07/2021 17:28, Khem Raj wrote: > This avoids crashes in libc when cmsg is null and refrencing msg s/refrencing/referencing > structure when it is null > > Signed-off-by: Khem Raj Patch looks ok just some nits below, thank for catching it. I will commit it shortly for you. 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 > No implicit checks. > #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 > > Same as before.