LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2009, 12:21 PM   #16
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231

i thought protected mode only applies to cross segment code/data.
for example you can execute any data that is in the code segment but cannot execute it in the data segment
 
Old 11-08-2009, 01:48 PM   #17
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by smeezekitty View Post
i thought protected mode only applies to cross segment code/data.
for example you can execute any data that is in the code segment but cannot execute it in the data segment
right
unless the local descriptor table is wrong some how
there is a asm example for writing self modifying code the trick is making the code and data segments overlap by changing the ELF header
 
Old 11-08-2009, 02:16 PM   #18
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Actually, I think the correct answer is yes it is dangerous, and so is C ... but only if you don't know what you're doing, and if you're not using a real OS. I remember crashing or BSODing Windoze so many times with simple C programs in programming class ... but the thing is, even if you run those same programs on Linux, it won't crash the system, it'll just say 'seg fault' most of the time.
 
Old 11-08-2009, 02:55 PM   #19
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by H_TeXMeX_H View Post
Actually, I think the correct answer is yes it is dangerous, and so is C ... but only if you don't know what you're doing, and if you're not using a real OS. I remember crashing or BSODing Windoze so many times with simple C programs in programming class ... but the thing is, even if you run those same programs on Linux, it won't crash the system, it'll just say 'seg fault' most of the time.
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
 
Old 11-08-2009, 03:05 PM   #20
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by smeezekitty View Post
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
Oh, most certainly ... and that was punishment enough, trust me. I mean we had to complete the assignment by the end of the class with all this crashing going on. Not to mention that the computers were PII or lower running W 95 or 98, and some were so slow that they were unusable or would crash on their own.
 
Old 11-08-2009, 03:06 PM   #21
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Quote:
but even if it BSoD'ed all you have to do is reboot and it will work normally again.
Linux: "Oh, it segfaulted, time to fire up gdb"
Windows 9x: "Damn, it BSODed and I just lost my entire environment"

One is clearly orders of magnitude superior than the other.

Last edited by tuxdev; 11-08-2009 at 03:08 PM.
 
Old 11-08-2009, 03:46 PM   #22
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by tuxdev View Post
I believe he's referring to thunks, JIT and such.. Without the NX bit set on a page, you can execute whatever you like on the stack or heap - the processor doesn't really care inherently, it's just memory.
for real mode your right BUT that's not how protected mode works
here is what intel says about how memory access works in protected mode
http://download.intel.com/design/int...ers/exc_ia.pdf
BTW
DOS 7 (windoze 95) was the last O/S to run in real mode

Last edited by rob.rice; 11-08-2009 at 03:49 PM.
 
Old 11-08-2009, 04:07 PM   #23
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rob.rice View Post
well you found a bug in gcc or the kernel
please report your bug to both the kernel and gcc maintainers
the data is being put in to the code segment or the local descriptor
tables are being written wrong

No, I've found a documented feature:

http://www.embeddedrelated.com/group.../show/5031.php ->

<your_function_return_type> __attribute__ ((section (".data"))) <your_function_name>(<your_function_args>);
 
Old 11-08-2009, 04:59 PM   #24
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
windows 3.1 was actually protected mode assisted codenamed "386 enhanced mode" where programs could general protection fault but it is also not completly protected mode.
 
Old 11-08-2009, 07:17 PM   #25
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
MrCode -

Your question has certain generated a lot of smoke, noise, half-truths and misinformation

And yes, even some genuine wisdom

Anyway, I think you can safely take away from this discussion:

1. No, you probably can't do any more "harm" with assembly than you can with a high-level language.

Software is software. At the end of the day, it makes little difference if it's written in assembly or a higher-level language. If the OS will let you trash the system, then just about any language will let you trash the system. For example, I can show you a .bat file that can trash Windows NT (no kidding!).

One could argue that "languages" like Java, C# and VB.Net give you additional "protection" - precisely because they're MORE than just "languages". They're a "language" (Java, C#, whatever) plus a "virtual machine" (the JVM, or the .Net runtime). And it's the virtual machine - NOT the "language" - that gives you the extra "protection".

2. Yes, "real mode" and "protected mode" are COMPLETELY different environments.

You simply can't compare the behavior of a C program under real-mode DOS with the behavior of the SAME C program under protected mode Windows.

Again: software is software: the C program under real mode is comparable to the ASM program in real mode; and the same for the C program vs ASM program under protected mode.

I encourage smeezekitty to experiment with DPMI. Both DJGCPP and OpenWatcom let you experiment with C/++ real mode vs. C/C++ protected mode:

http://www.delorie.com/djgpp/
http://openwatcom.com/

Protected mode programming is VERY (read: "fundamentally"!) DIFFERENT from real-mode programming.

It doesn't really matter whether the OS is Linux, Windows or even DOS/DPMI, or whether the language is C/C++ or assembly. What DOES matter is that the address expressed in your application is NOT the actual address used by the hardware.

Last edited by paulsm4; 11-08-2009 at 07:23 PM.
 
Old 11-08-2009, 08:58 PM   #26
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
 
Old 11-09-2009, 04:53 PM   #27
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
As for NX-bit keeping one safe from accidental execution, that's not entirely correct. As an example, return-into-libc is a whole class of BO which functions fine on an NX stack. At the end of the day, you can only do as much or as little harm in C/C++/asm as the system allows you to do. If you are allowed to send a command to format the hdd, you run that risk. If you're allowed to send some kind of wacky overclocking series of instructions which cause your hdd to simultaneously break the speed of light while your monitor flashes the morse code lyrics to boogey fever, thus creating a rift to the 1970s - well.. you get the picture. Seriously, it's very unlikely that you'll accidentally trash your system, but even if you do the worst that happens is you need to reinstall. Most hardware nowadays protects itself pretty well, and as long as said low-level format is recoverable you're just inconvenienced a lot, and more importantly learn "Don't do that"

Anyway, just one perspective.
 
Old 11-09-2009, 06:19 PM   #28
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864

Original Poster
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
1. No, you probably can't do any more "harm" with assembly than you can with a high-level language.
I figured, just wanted to make sure, though. I have heard of instances where hardware was damaged because of either poorly-written or buggy software, but I think that would mostly apply to things like embedded systems/firmware.

Quote:
2. Yes, "real mode" and "protected mode" are COMPLETELY different environments.
I'm reading a basic x86/NASM guide (that can be found here), and as I understand it, you really wouldn't want to program in real mode anyway, right? Not unless you were writing for some ancient 286 with 1MB |< of RAM, where you really have no choice...

Quote:
Originally Posted by smeezekitty View Post
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
I know that you can trash your file system using either of those commands (in DOS/UNIX-like systems respectively), I was just curious as to whether actual physical H/W damage could occur from poorly written software, but as others have said, this would be VERY hard to do...

Last edited by MrCode; 11-09-2009 at 06:23 PM.
 
Old 11-09-2009, 06:37 PM   #29
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by smeezekitty View Post
just a command can trash the system :
Code:
deltree C:\ for win / dos
rm -rf / for unix / linux
now really do not run those commands
I did a rm -r /usr from / I thought I was in /root/temp
luckily the package manager was in /sbin , I had the install disks
at hand and I figured out what I did before rebooting
 
Old 11-09-2009, 07:12 PM   #30
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
I'm reading a basic x86/NASM guide (that can be found here), and as I understand it, you really wouldn't want to program in real mode anyway, right? Not unless you were writing for some ancient 286 with 1MB |< of RAM, where you really have no choice...
real mode has some serious advantaged especially on a single tasking system.
for example:
you can do increadably fast screen writes by writing to B800:0 in real mode but in dos
you have to call a protected mode function that writes it for you, and that time could be significint!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ASM x32 vs ASM x64 Tegramon Programming 3 02-27-2008 02:26 PM
I/O in ASM Mercurius Programming 10 11-16-2006 07:02 PM
Not exactly a newbie, but still dangerous jhenager LinuxQuestions.org Member Intro 2 09-19-2005 02:51 PM
is this dangerous? Kendo1979 Linux - Security 3 05-17-2005 11:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration