buffer filled by kernel

Arkadiusz Miśkiewicz <[email protected]> Thu, 26 Jan 2012 23:07:30 +0100
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Hello,

I'm trying to do get xfs quota information set on linux, on xfs partition
for a user with uid 1520:

import ctypes

class fs_disk_quota_t(ctypes.Structure):
    __fields__ = [
        ("d_version", ctypes.c_char),
        ("d_flags", ctypes.c_char),
        ("d_fieldmask", ctypes.c_ushort),
        ("d_id", ctypes.c_uint32),
        ("d_blk_hardlimit", ctypes.c_uint64),
        ("d_blk_softlimit", ctypes.c_uint64),
        ("d_ino_hardlimit", ctypes.c_uint64),
        ("d_ino_softlimit", ctypes.c_uint64),
        ("d_bcount", ctypes.c_uint64),
        ("d_icount", ctypes.c_uint64),
        ("d_itimer", ctypes.c_int32),
        ("d_btimer", ctypes.c_int32),
        ("d_iwarns", ctypes.c_uint16),
        ("d_bwarns", ctypes.c_uint16),
        ("d_padding2", ctypes.c_int32),
        ("d_rtb_hardlimit", ctypes.c_uint64),
        ("d_rtb_softlimit", ctypes.c_uint64),
        ("d_rtbcount", ctypes.c_uint64),
        ("d_rtbtimer", ctypes.c_int32),
        ("d_rtbwarns", ctypes.c_uint16),
        ("d_padding3", ctypes.c_int16),
        ("d_padding4", ctypes.c_char * 8)
    ]

quota_o = fs_disk_quota_t()

lib.quotactl.restype = ctypes.c_int64
lib.quotactl.argtypes = [ctypes.c_int64, ctypes.c_char_p, ctypes.c_int64, 
ctypes.c_char_p]
lib.quotactl(ctypes.c_int64(5767936), "/dev/loop0", ctypes.c_int64(1520), 
ctypes.cast(ctypes.addressof(quota_o), ctypes.c_char_p))

print quota_o.d_blk_hardlimit.value


The problem is that the code segfaults immediately after quotactl ioctl is 
being called. Tried doing various things like:
lib.quotactl.argtypes = ... , ctypes.c_void_p);
lib.quotactl(..., ctypes.addressof(quota_o))

also pointer(quota_o), byref(quota_o) etc.


Any ideas what I'm doing wrong? python 2.7.2, glibc 2.14.1, kernel 3.3rc1


>From strace:

quotactl(Q_XGETQUOTA|USRQUOTA, "/dev/loop0", 1520, {version=1, 
flags=XFS_USER_QUOTA, fieldmask=0, id=1520, blk_hardlimit=1048576000, 
blk_softlimit=1048576000, ino_hardlimit=0, ino_softlimit=0, bcount=0, 
icount=0, ...}) = 0
--- {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3e800000} 
(Segmentation fault) ---

Unfortunately no debug symbols:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7e8d9b3 in _PyObject_GenericGetAttrWithDict () from 
/usr/lib64/libpython2.7.so.1.0
(gdb) bt
#0  0x00007ffff7e8d9b3 in _PyObject_GenericGetAttrWithDict () from 
/usr/lib64/libpython2.7.so.1.0
#1  0x00007ffff7ee9e7a in PyEval_EvalFrameEx () from 
/usr/lib64/libpython2.7.so.1.0
#2  0x00007ffff7eee305 in PyEval_EvalCodeEx () from 
/usr/lib64/libpython2.7.so.1.0
#3  0x00007ffff7eee452 in PyEval_EvalCode () from 
/usr/lib64/libpython2.7.so.1.0
#4  0x00007ffff7f095ec in ?? () from /usr/lib64/libpython2.7.so.1.0
#5  0x00007ffff7f0a3c0 in PyRun_FileExFlags () from 
/usr/lib64/libpython2.7.so.1.0
#6  0x00007ffff7f0ae3f in PyRun_SimpleFileExFlags () from 
/usr/lib64/libpython2.7.so.1.0
#7  0x00007ffff7f1c835 in Py_Main () from /usr/lib64/libpython2.7.so.1.0
#8  0x00007ffff7a6e28d in __libc_start_main () from /lib64/libc.so.6
#9  0x0000000000400669 in _start ()

How to reproduce? +- like this:

dd if=/dev/zero of=testfile bs=1M count=50
xfs_mkfs testfile
losetup -f /dev/loop0 testfile
run script above

-- 
Arkadiusz Miśkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/



------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d