From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 2025C384D15B for ; Fri, 26 Aug 2022 21:49:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2025C384D15B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-11e8b592421so2255957fac.0 for ; Fri, 26 Aug 2022 14:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=vi8TLJ3NpB4RSOKlQw3KnUrSdLqoD7hjHpe9ku74uJg=; b=BIeEgtsqPeWDglhA2g04AKXJK6WtQSuLy/pU5meiNhEXdZGcFScOA67hLpRq8CRzV1 D7DlNDCZhjVfcagfU86W8f0cGfXzwtWusWVMi2k4uHw543fiSnLKKJZiRSF+/K8vq7YL d59tia/J6U+Dbyqow2/W+T+m+wnanhxflIx+v0V6j/PKIwaxNwvrmtA6X9Oi/ibxBpPw ZMaCgcH2Ajp2lZhfwQZ3Vz4SkAhTXZAIX+Plt0QLq3QSqz5xewSdviKoLxlHEuWZYOGD +R/UG0UC+Lkp81VVjaXe3PudrdYzCQnnqR0Q7r4/p9sbdtFibLPo0mxlrk3H+nr4mRmV Jh6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=vi8TLJ3NpB4RSOKlQw3KnUrSdLqoD7hjHpe9ku74uJg=; b=ZE5DX9ZD+TBbe9Sw44c/nYJ0yxFKYWwSVAIANq2kZhJdosUHsD8mkbVMF3q7xJAN5a IxCuz1jp4WBdt6Ua0UWVnO560WpHL8Xd0CRMGqiwVpnGU1ysIMskfhhMi8MQcbRAfR7a dXp4aWgTqY7gNQMQgBtnybjHMK8nLUrxZHvCSds/lrrEurlwa6bbrP78pg/hGizEBoT5 GBLzYITkxn/tLxRjSdbrtHgra3/jJph6fw2VMmt6MNF3NGtaB/EKTrLlZIXhdKi2wa/b 1UbgsdKfrIVpULfdAnRJTBVQDMbnLvkaEJadPkINt8wFtxoPCm2lRu6eI4R37i4TB/wl LwMg== X-Gm-Message-State: ACgBeo3V4fdGhmU+PtfWTSajVh8Zy9NUcAdcP4MagWfyas07ZcVZzHlB DUj0XrYnOG66FZrabcMlFtHWHCTXsH54Fw== X-Google-Smtp-Source: AA6agR6PCgusaP9ab14d0rsqYLHj57JRtupCHMgn0fz1ReLWXIDJw3nL109bZWzrtxXgsNxurJIe/A== X-Received: by 2002:a05:6870:888d:b0:10d:6b96:2074 with SMTP id m13-20020a056870888d00b0010d6b962074mr2815277oam.218.1661550548307; Fri, 26 Aug 2022 14:49:08 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:745e:29d4:72eb:77d8:14cb? ([2804:1b3:a7c0:745e:29d4:72eb:77d8:14cb]) by smtp.gmail.com with ESMTPSA id l9-20020a4ae389000000b0044b47bb023fsm1586890oov.37.2022.08.26.14.49.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 14:49:08 -0700 (PDT) Message-ID: Date: Fri, 26 Aug 2022 18:49:05 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: glibc 2.36: syslog() with LOG_PERROR and a message > 1024 ends up reading invalid memory Content-Language: en-US To: Aleksander Morgado , libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 26/08/22 17:12, Aleksander Morgado via Libc-alpha wrote: > Hey all, > > I'm debugging memory issues in ModemManager running it under valgrind > and I believe I've hit a bug in the syslog() implementation in glibc > 2.36 when using LOG_PERROR. > > The call triggering the invalid error is the __dprintf() call in line 230: > https://elixir.bootlin.com/glibc/glibc-2.36/source/misc/syslog.c#L230 > > /* Output to stderr if requested. */ > if (LogStat & LOG_PERROR) > __dprintf (STDERR_FILENO, "%s%s", buf + msgoff, > "\n" + (buf[bufsize - 1] == '\n')); > > If I'm reading the code right, I believe that bufsize is only set to a > value != 0 if the logic ends up using the static "bufs" buffer. If the > logic needs to allocate memory for a longer buffer, bufsize is never > initialized, so the __dprintf call above tries to access buf[-1]. > > Valgrind reports the problem as: > > valgrind ./test-syslog-valgrind-error > ==20815== Memcheck, a memory error detector > ==20815== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. > ==20815== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info > ==20815== Command: ./test-syslog-valgrind-error > ==20815== > ==20815== Invalid read of size 1 > ==20815== at 0x4985E58: __vsyslog_internal (syslog.c:230) > ==20815== by 0x4986299: syslog (syslog.c:90) > ==20815== by 0x1091AB: main (in /home/aleksander/test-syslog-valgrind-error) > ==20815== Address 0x4a71baf is 1 bytes before a block of size 29 alloc'd > ==20815== at 0x4841888: malloc (in > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==20815== by 0x4985DCC: __vsyslog_internal (syslog.c:206) > ==20815== by 0x4986299: syslog (syslog.c:90) > ==20815== by 0x1091AB: main (in /home/aleksander/test-syslog-valgrind-error) > ==20815== > ==20815== Conditional jump or move depends on uninitialised value(s) > ==20815== at 0x4847D09: strlen (in > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==20815== by 0x48E15C7: __vfprintf_internal (vfprintf-process-arg.c:397) > ==20815== by 0x49016F9: __vdprintf_internal (iovdprintf.c:54) > ==20815== by 0x48D4D89: dprintf (dprintf.c:30) > ==20815== by 0x4985E82: __vsyslog_internal (syslog.c:230) > ==20815== by 0x4986299: syslog (syslog.c:90) > ==20815== by 0x1091AB: main (in /home/aleksander/test-syslog-valgrind-error) > ==20815== > > Attached is a simple tester. > > Cheers > Thanks, in fact this is not the only issue, the message is not log for large buffers. I will take of it, I should have added tests for large buffers on tst-syslog as well.