Bug 281059 - Cannot connect to Oracle using valgrind
Summary: Cannot connect to Oracle using valgrind
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.5.0
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-30 17:47 UTC by Pranay
Modified: 2011-10-13 20:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pranay 2011-08-30 17:47:21 UTC
Version:           3.5.0
OS:                Linux

>> valgrind --version
>> valgrind-3.5.0

>> uname -a
Linux <servername> 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64

When i run sqlplus without valgrind, it works - see below 

>> sqlplus user/pass
SQL*Plus: Release 10.2.0.4.0 - Production on Tue Aug 30 11:40:51 2011
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

When i run sqlplus using valgrind, i get an error as below -

>> valgrind sqlplus user/pass
valgrind: sqlplus: command not found

Looks like, running it along with valgrind, doesn't use PATH appropriately, so to avoid it, i give full path as below, but still get an error -

>> valgrind /u01/app/oracle/product/10.2.0/bin/sqlplus user/pass
valgrind: /u01/app/oracle/product/10.2.0/bin/sqlplus: Permission denied

I dont know how to make this work. All the processes in our application connect to Oracle DB and unless this works, i wont be able to use this too.

Reproducible: Always

Steps to Reproduce:
I have described the steps in the details section.

Actual Results:  
I am unable to connect to Oracle DB.

Expected Results:  
One should be able to connect to ORACLE using valgrind.
Comment 1 Philippe Waroquiers 2011-08-30 20:07:34 UTC
(In reply to comment #0)

> Actual Results:  
> I am unable to connect to Oracle DB.
> 
> Expected Results:  
> One should be able to connect to ORACLE using valgrind.

At work, we are using Valgrind on a big application which connects to Oracle
without problem. I however never tried to use Valgrind on sqlplus.

I was able to reproduce similar symptoms by having an executable file
that only has "x" permission (so, not readable and not writable).
(see below). Such file is found by the shell and can be executed, but
Valgrind can't execute it : to execute it, Valgrind needs to read the
instructions.

You can check if this is the same problem by doing
ls -l /u01/app/oracle/product/10.2.0/bin/sqlplus

It is however unclear why you would launch valgrind on sqlplus.
In which language is your application written ? 
I guess that if it is written in pl/sql, Valgrind will not be
of a lot of help.


[philippe@soleil gdbserver_tests]$ ls -l ./x
---x--x--x. 1 philippe philippe 9236 2011-08-30 21:55 ./x
[philippe@soleil gdbserver_tests]$ which x
./x
[philippe@soleil gdbserver_tests]$ x
breakme function called from line 19
before reading 0/4/8
u: Expected value at 0
f: Expected value at 4
d: Expected value at 8
before writing 0
before writing 4
before writing 8
after writing 8
value UndeFineD
before rewriting 0
before rewriting 4
before rewriting 8
value 0nde4ine8
[philippe@soleil gdbserver_tests]$ valgrind ./x
valgrind: ./x: Permission denied
[philippe@soleil gdbserver_tests]$ valgrind x
valgrind: x: command not found
[philippe@soleil gdbserver_tests]$
Comment 2 Pranay 2011-08-31 03:51:42 UTC
 
Hi,
 
We dont use sqlplus directly to connect to the database in our application. We use "EXEC SQL CONNECT :user_id USING :database_name;" in our ProCpp code to connect. However, i was getting the below error when i ran the same executable using valgrind -
 
Error: DBPersistence::Connect  ORA-12546: TNS:permission denied    ---- this is thrown when the above command is executed....
 
In an attempt to dig further, i thought of trying to connect to Oracle using sqlplus and thought that the issue is similar (i shouldn't say similar, rather that the cause could be similar).
 
As you said, i changed the permission of sqlplus and granted read permission to "others" ...
 
-rwxr-xr-x 1 oracle dba 7327 Dec  1  2008 /u01/app/oracle/product/10.2.0/bin/sqlplus

But when i ran the executable again, i got the same TNS:permission denied error. (which was expected as the exe isn't using sqlplus client to connect to Oracle)
 
When i ran sqlplus using valgrind, it gave me the below -
 
>> valgrind sqlplus user/pass
==24985== Memcheck, a memory error detector
==24985== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==24985== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
*
*
ORA-12546: TNS:permission denied

 
Any comments would be appreciated... i am in urgent need to get this working since our app is on Linux and has issues with memory leak.
 
thx
pranay
 
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: pranay_tonpay@yahoo.com
Sent: Wednesday, August 31, 2011 1:37 AM
Subject: [Bug 281059] Cannot connect to Oracle using valgrind

https://bugs.kde.org/show_bug.cgi?id=281059


Philippe Waroquiers <philippe.waroquiers@skynet.be> changed:

          What    |Removed                    |Added
----------------------------------------------------------------------------
                CC|                            |philippe.waroquiers@skynet.
                  |                            |be




--- Comment #1 from Philippe Waroquiers <philippe waroquiers skynet be>  2011-08-30 20:07:34 ---
(In reply to comment #0)

> Actual Results:  
> I am unable to connect to Oracle DB.
> 
> Expected Results:  
> One should be able to connect to ORACLE using valgrind.

At work, we are using Valgrind on a big application which connects to Oracle
without problem. I however never tried to use Valgrind on sqlplus.

I was able to reproduce similar symptoms by having an executable file
that only has "x" permission (so, not readable and not writable).
(see below). Such file is found by the shell and can be executed, but
Valgrind can't execute it : to execute it, Valgrind needs to read the
instructions.

You can check if this is the same problem by doing
ls -l /u01/app/oracle/product/10.2.0/bin/sqlplus

It is however unclear why you would launch valgrind on sqlplus.
In which language is your application written ? 
I guess that if it is written in pl/sql, Valgrind will not be
of a lot of help.


[philippe@soleil gdbserver_tests]$ ls -l ./x
---x--x--x. 1 philippe philippe 9236 2011-08-30 21:55 ./x
[philippe@soleil gdbserver_tests]$ which x
./x
[philippe@soleil gdbserver_tests]$ x
breakme function called from line 19
before reading 0/4/8
u: Expected value at 0
f: Expected value at 4
d: Expected value at 8
before writing 0
before writing 4
before writing 8
after writing 8
value UndeFineD
before rewriting 0
before rewriting 4
before rewriting 8
value 0nde4ine8
[philippe@soleil gdbserver_tests]$ valgrind ./x
valgrind: ./x: Permission denied
[philippe@soleil gdbserver_tests]$ valgrind x
valgrind: x: command not found
[philippe@soleil gdbserver_tests]$
Comment 3 Philippe Waroquiers 2011-08-31 06:04:30 UTC
(In reply to comment #2)

> When i ran sqlplus using valgrind, it gave me the below -
> 
> >> valgrind sqlplus user/pass
> ==24985== Memcheck, a memory error detector
> ==24985== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
> ==24985== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
> *
> *
> ORA-12546: TNS:permission denied

I only have limited Oracle knowledge.
But according to 
http://www.dba-oracle.com/security/removing_permissions.htm
read permissions are removed from Oracle executables so as to force
to use IPC or TCP connections.

If I understood correctly the above page, you should
either set read permissions on some other Oracle executables
or use another technique to connect to Oracle.

An alternative way to investigate is to trace the system calls (using e.g. strace)
of a small executable only doing the connect to Oracle, and
see which system calls are failing running with Valgrind, when comparing with
the native run.
Comment 4 Pranay 2011-08-31 15:45:52 UTC
 
thx Philippe, i found how to get over that issue by setting TWO_TASK and setting an entry in tnsnames.ora file... it worked.

From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: pranay_tonpay@yahoo.com
Sent: Wednesday, August 31, 2011 11:34 AM
Subject: [Bug 281059] Cannot connect to Oracle using valgrind

https://bugs.kde.org/show_bug.cgi?id=281059





--- Comment #3 from Philippe Waroquiers <philippe waroquiers skynet be>  2011-08-31 06:04:30 ---
(In reply to comment #2)

> When i ran sqlplus using valgrind, it gave me the below -
> 
> >> valgrind sqlplus user/pass
> ==24985== Memcheck, a memory error detector
> ==24985== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
> ==24985== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
> *
> *
> ORA-12546: TNS:permission denied

I only have limited Oracle knowledge.
But according to 
http://www.dba-oracle.com/security/removing_permissions.htm
read permissions are removed from Oracle executables so as to force
to use IPC or TCP connections.

If I understood correctly the above page, you should
either set read permissions on some other Oracle executables
or use another technique to connect to Oracle.

An alternative way to investigate is to trace the system calls (using e.g.
strace)
of a small executable only doing the connect to Oracle, and
see which system calls are failing running with Valgrind, when comparing with
the native run.
Comment 5 Julian Seward 2011-10-13 08:57:25 UTC
Might be some kind of setuid problem.  We've seen those before.
Comment 6 Philippe Waroquiers 2011-10-13 20:57:18 UTC
(In reply to comment #5)
> Might be some kind of setuid problem.  We've seen those before.

The conclusions of the analysis were: for security reasons, some
Oracle executables have only the execute bit set (i.e. the executable
is not readable).

The shell will execute such a "execute" only file, but Valgrind will not
as Valgrind checks that the executable has both r and x bit
in launcher-linux.c
   if (access(fullname, R_OK|X_OK) == 0)

A 'x' only file will be silently ignored by Valgrind, and will result
in 'command not found'.

What could be done is to have the launcher reporting an error if it finds
a file which is executable but not readable.

Something like:
    if (access(fullname, X_OK) == 0)
         if (access(fullname, R_OK) == 0)
            return fullname;
         else
             ... error : valgrind cannot execute an
             ... executable file if the file is not readable