Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undocumented unaligned pointer error messages #16154

Open
p5pRT opened this issue Sep 17, 2017 · 8 comments
Open

Undocumented unaligned pointer error messages #16154

p5pRT opened this issue Sep 17, 2017 · 8 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Sep 17, 2017

Migrated from rt.perl.org#132112 (status was 'open')

Searchable as RT132112$

@p5pRT
Copy link
Author

p5pRT commented Sep 17, 2017

From @jkeenan

At lines 1313 and 1320 of malloc.c, there appear error messages which
are neither documented in pod/perldiag.pod nor (AFAICT) exercised in the
test suite.

  "Unaligned pointer in the free chain 0x%" UVxf "\n"

  "Unaligned \"next\" pointer in the free "
  "chain 0x%" UVxf " at 0x%" UVxf "\n",

#####
Malloc_t
Perl_malloc(size_t nbytes)
{
...
  /* remove from linked list */
#ifdef DEBUGGING
  if ( (PTR2UV(p) & (MEM_ALIGNBYTES - 1))
  /* Can't get this low */
  || (p && PTR2UV(p) < (1<<LOG_OF_MIN_ARENA)) ) {
  dTHX;
  PerlIO_printf(PerlIO_stderr(),
  "Unaligned pointer in the free chain 0x%" UVxf "\n",
  PTR2UV(p));
  }
  if ( (PTR2UV(p->ov_next) & (MEM_ALIGNBYTES - 1))
  || (p->ov_next && PTR2UV(p->ov_next) < (1<<LOG_OF_MIN_ARENA)) ) {
  dTHX;
  PerlIO_printf(PerlIO_stderr(),
  "Unaligned \"next\" pointer in the free "
  "chain 0x%" UVxf " at 0x%" UVxf "\n",
  PTR2UV(p->ov_next), PTR2UV(p));
  }
#endif
#####

How should they be documented?

Can they be exercised in the test suite?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Sep 17, 2017

From @jkeenan

Summary of my perl5 (revision 5 version 27 subversion 4) configuration​:
  Commit id​: e271727
  Platform​:
  osname=linux
  osvers=4.4.0-93-generic
  archname=x86_64-linux
  uname='linux zareason 4.4.0-93-generic #116-ubuntu smp fri aug 11 21​:17​:51 utc 2017 x86_64 x86_64 x86_64 gnulinux '
  config_args='-des -Dusedevel'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=undef
  usemultiplicity=undef
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=n
  default_inc_excludes_dot=define
  bincompat5005=undef
  Compiler​:
  cc='cc'
  ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
  optimize='-O2'
  cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion=''
  gccversion='5.4.0 20160609'
  gccosandvers=''
  intsize=4
  longsize=8
  ptrsize=8
  doublesize=8
  byteorder=12345678
  doublekind=3
  d_longlong=define
  longlongsize=8
  d_longdbl=define
  longdblsize=16
  longdblkind=3
  ivtype='long'
  ivsize=8
  nvtype='double'
  nvsize=8
  Off_t='off_t'
  lseeksize=8
  alignbytes=8
  prototype=define
  Linker and Libraries​:
  ld='cc'
  ldflags =' -fstack-protector-strong -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
  libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
  perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  libc=libc-2.23.so
  so=so
  useshrplib=false
  libperl=libperl.a
  gnulibc_version='2.23'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs
  dlext=so
  d_dlsymun=undef
  ccdlflags='-Wl,-E'
  cccdlflags='-fPIC'
  lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Characteristics of this binary (from libperl)​:
  Compile-time options​:
  HAS_TIMES
  PERLIO_LAYERS
  PERL_COPY_ON_WRITE
  PERL_DONT_CREATE_GVSV
  PERL_MALLOC_WRAP
  PERL_OP_PARENT
  PERL_PRESERVE_IVUV
  PERL_USE_DEVEL
  USE_64_BIT_ALL
  USE_64_BIT_INT
  USE_LARGE_FILES
  USE_LOCALE
  USE_LOCALE_COLLATE
  USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC
  USE_LOCALE_TIME
  USE_PERLIO
  USE_PERL_ATOF
  Built under linux
  Compiled at Sep 16 2017 10​:17​:33
  %ENV​:
  PERLBREW_BASHRC_VERSION="0.78"
  PERLBREW_HOME="/home/jkeenan/.perlbrew"
  PERLBREW_MANPATH="/home/jkeenan/perl5/perlbrew/perls/perl-5.26.0/man"
  PERLBREW_PATH="/home/jkeenan/perl5/perlbrew/bin​:/home/jkeenan/perl5/perlbrew/perls/perl-5.26.0/bin"
  PERLBREW_PERL="perl-5.26.0"
  PERLBREW_ROOT="/home/jkeenan/perl5/perlbrew"
  PERLBREW_VERSION="0.78"
  PERL_WORKDIR="/home/jkeenan/gitwork/perl"
  @​INC​:
  lib
  /usr/local/lib/perl5/site_perl/5.27.4/x86_64-linux
  /usr/local/lib/perl5/site_perl/5.27.4
  /usr/local/lib/perl5/5.27.4/x86_64-linux
  /usr/local/lib/perl5/5.27.4

@p5pRT
Copy link
Author

p5pRT commented Nov 8, 2017

From @jkeenan

On Sun, 17 Sep 2017 16​:46​:56 GMT, jkeenan@​pobox.com wrote​:

At lines 1313 and 1320 of malloc.c, there appear error messages which
are neither documented in pod/perldiag.pod nor (AFAICT) exercised in the
test suite.

           "Unaligned pointer in the free chain 0x%" UVxf "\\n"

           "Unaligned \\"next\\" pointer in the free "
           "chain 0x%" UVxf " at 0x%" UVxf "\\n"\,

#####
Malloc_t
Perl_malloc(size_t nbytes)
{
...
/* remove from linked list */
#ifdef DEBUGGING
if ( (PTR2UV(p) & (MEM_ALIGNBYTES - 1))
/* Can't get this low */
|| (p && PTR2UV(p) < (1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned pointer in the free chain 0x%" UVxf "\n",
PTR2UV(p));
}
if ( (PTR2UV(p->ov_next) & (MEM_ALIGNBYTES - 1))
|| (p->ov_next && PTR2UV(p->ov_next) < (1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned \"next\" pointer in the free "
"chain 0x%" UVxf " at 0x%" UVxf "\n",
PTR2UV(p->ov_next), PTR2UV(p));
}
#endif
#####

How should they be documented?

Can they be exercised in the test suite?

Can anyone comment on the questions above?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 8, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 8, 2017

From @tonycoz

On Sun, Sep 17, 2017 at 09​:46​:56AM -0700, James E Keenan wrote​:

# New Ticket Created by James E Keenan
# Please include the string​: [perl #132112]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=132112 >

At lines 1313 and 1320 of malloc.c, there appear error messages which
are neither documented in pod/perldiag.pod nor (AFAICT) exercised in the
test suite.

           "Unaligned pointer in the free chain 0x%" UVxf "\\n"

           "Unaligned \\"next\\" pointer in the free "
           "chain 0x%" UVxf " at 0x%" UVxf "\\n"\,

#####
Malloc_t
Perl_malloc(size_t nbytes)
{
...
/* remove from linked list */
#ifdef DEBUGGING
if ( (PTR2UV(p) & (MEM_ALIGNBYTES - 1))
/* Can't get this low */
|| (p && PTR2UV(p) < (1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned pointer in the free chain 0x%" UVxf "\n",
PTR2UV(p));
}
if ( (PTR2UV(p->ov_next) & (MEM_ALIGNBYTES - 1))
|| (p->ov_next && PTR2UV(p->ov_next) < (1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned \"next\" pointer in the free "
"chain 0x%" UVxf " at 0x%" UVxf "\n",
PTR2UV(p->ov_next), PTR2UV(p));
}
#endif
#####

How should they be documented?

We could add them to perldiag.

Can they be exercised in the test suite?

No. They depend on building with -Dusemymalloc *and* on the arena
being corrupted.

The first is unlikely, I don't know of any platform where we build
with -Dusemymalloc by default. The second indicates some other bug is
present.

Tony

@p5pRT
Copy link
Author

p5pRT commented Nov 8, 2017

From @jkeenan

On Wed, 08 Nov 2017 03​:40​:05 GMT, tonyc wrote​:

On Sun, Sep 17, 2017 at 09​:46​:56AM -0700, James E Keenan wrote​:

# New Ticket Created by James E Keenan
# Please include the string​: [perl #132112]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=132112 >

At lines 1313 and 1320 of malloc.c, there appear error messages which
are neither documented in pod/perldiag.pod nor (AFAICT) exercised in
the
test suite.

"Unaligned pointer in the free chain 0x%" UVxf "\n"

"Unaligned \"next\" pointer in the free "
"chain 0x%" UVxf " at 0x%" UVxf "\n",

#####
Malloc_t
Perl_malloc(size_t nbytes)
{
...
/* remove from linked list */
#ifdef DEBUGGING
if ( (PTR2UV(p) & (MEM_ALIGNBYTES - 1))
/* Can't get this low */
|| (p && PTR2UV(p) < (1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned pointer in the free chain 0x%" UVxf "\n",
PTR2UV(p));
}
if ( (PTR2UV(p->ov_next) & (MEM_ALIGNBYTES - 1))
|| (p->ov_next && PTR2UV(p->ov_next) <
(1<<LOG_OF_MIN_ARENA)) ) {
dTHX;
PerlIO_printf(PerlIO_stderr(),
"Unaligned \"next\" pointer in the free "
"chain 0x%" UVxf " at 0x%" UVxf "\n",
PTR2UV(p->ov_next), PTR2UV(p));
}
#endif
#####

How should they be documented?

We could add them to perldiag.

Can they be exercised in the test suite?

No. They depend on building with -Dusemymalloc *and* on the arena
being corrupted.

The first is unlikely, I don't know of any platform where we build
with -Dusemymalloc by default. The second indicates some other bug is
present.

Tony

Attached is a patch which passes 'make test_porting' but whose content needs improvement. Please review.

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 8, 2017

From @jkeenan

132112-0001-Document-two-warnings-in-Perl_malloc.patch
From 5eb2b382fcac28cb8e656bba882bdae75f865955 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Wed, 8 Nov 2017 07:23:40 -0500
Subject: [PATCH] Document two warnings in Perl_malloc.

For: RT #132112
---
 pod/perldiag.pod | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 2cf2040..2eddf4c 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -6230,6 +6230,16 @@ certain type.  Arrays must be @NAME or C<@{EXPR}>.  Hashes must be
 (F) Your machine doesn't implement the umask function and you tried to
 use it to restrict permissions for yourself (EXPR & 0700).
 
+=item Unaligned "next" pointer in the free chain 0x% at 0x%
+
+(W malloc) In a perl built with C<-Dusemymalloc>, there was a problem when
+removing an item from a linked list.
+
+=item Unaligned pointer in the free chain 0x%
+
+(W malloc) In a perl built with C<-Dusemymalloc>, there was a problem when
+removing an item from a linked list.
+
 =item Unbalanced context: %d more PUSHes than POPs
 
 (S internal) The exit code detected an internal inconsistency in how
-- 
2.7.4

@jkeenan
Copy link
Contributor

jkeenan commented Jan 31, 2020

@iabyn @tonycoz Could you review the patch to pod/perldiag.pod I submitted for this ticket back in 2017?

Thank you very much.
Jim Keenan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants