From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 414023858C5F for ; Fri, 19 May 2023 11:55:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 414023858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684497331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3SQ9WNn8I/IyWZNLZZXtNrR5H1nq/gxjoPT1bCq5NNc=; b=BMTOkRDV3cC0Qi2ZlKpFD1+bsjhRKg0Hqs99c9K7jE3720tSEko09pcnyZv6jR0jII+mB5 5tDnHda28j0fLSO6lxyTYlF9GWYNWgk/FzMKpxB+TPfQ8OR5Fl6Ias/IFSiQ0kqPEwXr+j f8SJ6wfCLAa3ziyQFZ+JCwW9ClymamM= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-JX0nGXziOQy-Uc-DxcuFTg-1; Fri, 19 May 2023 07:55:31 -0400 X-MC-Unique: JX0nGXziOQy-Uc-DxcuFTg-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-561b792a58dso16568647b3.0 for ; Fri, 19 May 2023 04:55:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684497330; x=1687089330; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3SQ9WNn8I/IyWZNLZZXtNrR5H1nq/gxjoPT1bCq5NNc=; b=CJDRS9JEpWdxvm87LzLtBwzu/sHkXxxj1vuKOu2fgNuaY2Xa6vd14ppTzKGS8gKmHQ cWIB33UHcug+VSmmaI50+BPkRXlhfHhI0rjzPfipG189cF3J2fpeyEaGo3kPspned4de uOkMVMT75+ONH2389tdVSco5YdjuBvI8bK7qS4v8b5qGloXY7fYGyQyS1Eqdk34RyDX0 sDzoGOeoc4+BX4+vA2VBchzVAONwRkXKn/4wdRXEf1wGQxFHz3MfKLZ0MiL9OaXkhp3Z 7oKbMSRUsv6PcK/ej8VY7f1qUGXUwowR9oJDNqVf3UpUUYNGlcFRehMYFXc9IEt2E6Mw rgCg== X-Gm-Message-State: AC+VfDzrUU8i+R5Tkv0BuXhZxzCM60kkOzL4ZQPkVV61778/hjfd798t d12PbARYOynNtJVgpCkJl/FEjjW4SzEftXYW9WfxdS1myBr2gv1hESbOcsKItrrIHPayVxT6+ea 8rm1yj1Yiwf9UUY+pP9bUmRCpZzro X-Received: by 2002:a81:4c53:0:b0:561:94a9:f9f7 with SMTP id z80-20020a814c53000000b0056194a9f9f7mr1407336ywa.20.1684497330071; Fri, 19 May 2023 04:55:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hdCwpMk32NB5urJzO/llvzpUERO0zu4j/Jczr0EMXhzvPr1//H85Vde/8MalWahPt8bf2JQ== X-Received: by 2002:a81:4c53:0:b0:561:94a9:f9f7 with SMTP id z80-20020a814c53000000b0056194a9f9f7mr1407318ywa.20.1684497329801; Fri, 19 May 2023 04:55:29 -0700 (PDT) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id w203-20020a8149d4000000b0054fbadd96c4sm1094893ywa.126.2023.05.19.04.55.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 May 2023 04:55:29 -0700 (PDT) Message-ID: <293741fd-f97a-0b23-6487-20253c4608fb@redhat.com> Date: Fri, 19 May 2023 07:55:28 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] Increase judgment on buf. To: Adhemerval Zanella Netto , Peng Fan , libc-alpha@sourceware.org Cc: Xi Ruoyao References: <20230519035713.3453563-1-fanpeng@loongson.cn> <374d9752-5a9b-15b2-058f-62943e6c7a33@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <374d9752-5a9b-15b2-058f-62943e6c7a33@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,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 server2.sourceware.org List-Id: On 5/19/23 07:48, Adhemerval Zanella Netto via Libc-alpha wrote: > > > On 19/05/23 00:57, Peng Fan wrote: >> When buf is empty, if it is not checked, the subsequent assignment >> operation will trigger a page fault. This is unnecessary. >> >> Signed-off-by: lixing >> Signed-off-by: Peng Fan > > The stat family is explicitly marked with nonnull for the input struct > stat buffer, and calling with a NULL argument is an UB. Agreed, and "Style and Conventions" https://sourceware.org/glibc/wiki/Style_and_Conventions says: https://sourceware.org/glibc/wiki/Style_and_Conventions#Bugs_in_the_user_program We should fail catastrophically and early in the case of user bugs. The segfault generates a core dump at exactly the right point to debug the UB. >> --- >> sysdeps/unix/sysv/linux/fstatat64.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c >> index 3509d3ca6d..b635a8299a 100644 >> --- a/sysdeps/unix/sysv/linux/fstatat64.c >> +++ b/sysdeps/unix/sysv/linux/fstatat64.c >> @@ -52,9 +52,13 @@ fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, >> { >> /* 32-bit kABI with default 64-bit time_t, e.g. arc, riscv32. Also >> 64-bit time_t support is done through statx syscall. */ >> - struct statx tmp; >> + struct statx tmp, *ptr; >> + if (buf) >> + ptr = &tmp; >> + else >> + ptr = NULL; >> int r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, >> - STATX_BASIC_STATS, &tmp); >> + STATX_BASIC_STATS, ptr); >> if (r != 0) >> return r; >> > -- Cheers, Carlos.