🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #599

Re: A Fatal Concertina Flaw?

#599
From: Waldek Hebisch
Date: Sun, 08 Nov 2026 22:12
197 lines
10569 bytes
John Savard <quadibloc@invalid.com> wrote:
> On Sun, 8 Nov 2026 15:55:42 -0000 (UTC), antispam@fricas.org (Waldek
> Hebisch) wrote:
> 
>>I wonder if you know:
>>1) Successors to 360 have PC-relative addressing, so using BALR to
>>   capture PC usually is not needed.
> 
> Concertina II has PC-relative addressing, but it still also uses base
> registers for most addressing. A subroutine call with a base-relative
> destination address can be used in place of a BALR instruction to
> capture an address value.

Sure, you may need to load PC to register.  Using something like
BALR is a bit problematic.  First, if there is a fixed register
to store return address, then BALR would overwrite it before you
had chance to save it.  Second, BALR takes target address in
register, so to land after current instruction you need to
already know that you want to compute.  So you either need a
special case oe use version which take relative displacement
instead of register argument.  Third, modern hardware commonly
have hardware stack of return addresses.  BALR not matched
with return causes misalignment of hardware return stack
which may lead to multiple mispredicted returns.  The
3 problems above means that normally capturing PC must be
a special case, so it is natural to treat it as a speparate
instruction (even if you want to hijack one of BALR
encoding and use it for the new instruction).

>>2) Save areas are normally allocated on the stack
> 
> I know that's how most PCs work. The 360 did not have a stack at all
> in the old days. Of course, a stack can be implemented even without an
> explicit stack pointer. And I presumed this was what the successors to
> the 360 might do; define one register as the one in which a pointer to
> the save area is passed.

OS360 (and IIUC other systems from IBM) defined really baroque
calling convention.  A call at PL/1 level led to call of one
or maybe 2 machine level subroutines to handle the convention.
In particular save areas were allocated using dynamic memory
allocation.  Logically you get a stack, but at lower level it
was a linked list.  The effect was that PL/1 function/subroutine
calls were quite slow.

Modern systems use much more efficient calling conventions.
Note that hardwarwise several modern systems have essentially
the same support for stack(s) as 360.  For example, on Risc-V
common convention is that register x2 is used as a stack pointer.
But you can use any other register (or none if you do not need
stack).  Function prologue on Risc-V looks like:

        addi    sp, sp, -64
        sd      s1, 0(sp)
        sd      ra, 56(sp)
        sd      s8, 48(sp)
        sd      s7, 40(sp)
        sd      s4, 32(sp)
        sd      s3, 24(sp)
        sd      s2, 16(sp)

Above sp is alternative name for x2 (that is conventional stack
pointer), ra is alternative name for x1 (that is conventianal
register used to save return address).  'sd' stores 8 byte
content of register at the adress being sum of numerical
offset and base.  AFAICS all instruction above can be easily
translated to 360 (modulo need for extra free register).

And yes, modern 360 uses similar calling convention.  Note that
this is pure software.  On old 360 one needs to fight a bit
restrictions on instruction set: to add a constant to register
one may use LA (load address), but that only allows positive
increments.  So one way or another one needs extra register.
For example one can load constant to extra register using LA,
and then use register subtraction to adjust stack pointer.
In corresponding epilogue one needs to add positive constant
so LA works fine.  Alternatively, one could use stack which
grows toward higher addresses.  Then adjustment in prologue
can be done using LA, in epilogue registers used by the
function are no longer needed, so we should have a free
registers.  But in prologue we can not use negative
displacements, so we would have to store registers before
adjusting stack pointer.  That needs some cooperation from
operating system: system should not interpret such stores
as stack ovefolow and should not store anything in zone
just above stack pointer (Unix signals normally create
fake stack frame there).

Actual sorting or restoring of registers is easier on 360
thanks to STM and LDM.

While need for a free register looks nasty at first, poor
support for constants on 360 means that need for extra register
to load constant into it is requent, so mandating a free
register at function/subroutine entry looks reasonable.  Also,
address manipulations needed for PIC (position independent code)
need extra register.

IIUC you are trying to add decent support for constants to
your architecture, in such case need to extra will vanish
IIRC also successors to 360 got reasnable support for
constants, so function prologue does not need extra register.
However, I think that PIC in 64 bit mode needs a register.

Anyway, any hardware problem with stack on 360 are due to
insistence on positive displacements combined with lack of
support for constant arguments in most of instructions.
And those problems are solved in succesor machine and even
on original 360 workaround is reasonably simple.

>>3) If for some reason you want save area in fixed place you can
>>   load its address to register.  Save area does not have to be very
>>   close to the code (but if it is far away then you need to provide
>>   more bits in the instruction).
> 
> Huh? Can't I just use a different base register if they're far away?

You need to load it first.  If you compute the address based on PC,
then clearly number of bits needed to express the difference
depends on the distance.  You can reserve one register just for
purpose of storing base to save areas, but then you have effectively
wasted a register.  So it is not clear what would you gain by
using such save area instead of using the register as stack pointer
and allocating save area on the stack?

>>4) While security folks insist on separate code and data areas,
>>   there is still a lot of code that mixes them.  And arguably,
>>   if language checks memory accesses, then separtation does not
>>   provide extra security.
> 
> That argument is fallacious, since a software barrier has the obvious
> potential of being bypassed if a way to sneak in machine code can be
> found.

The point is that if you assume that attacker can break existing
software berriers and modify pretty arbitrary writable locations
in memory, then lack of execute permission in most cases is just
a modest annayance.  Sure, in rare cases lack of execute
permission may stop the attack.

>>   To explain this a bit more: popular
>>   alternative to dynamically generated code is use of function
>>   pointers or intrpretive execution.  But of course, overwriting
>>   interpretive code is as bad as overwriting native code.
> 
> It's _almost_ as bad, since, of course, the interpreter can impose
> additional limits that the hardware instruction set does not impose.

So you are beliving that easy software checks will fail, but that
hard one will save you?  Note that in first case you need to
check operations work accoring to laguage rules: that array
accesses are in bounds, that memory allocation actually got
memory, that type tags match.  Those checks are realtively easy
to implement, they just decrease speed (say program may run at
half or one third of speed of program without checks).  When
you have malicious interpreted code it can do anything that
legal code can do, so basically all you can do is to say
"no legal program will ever to this" or at best "this program
will never do this".  But in real life program are used to
do interesting things, so attacker will have access to
a lot of things.

>>   Similarly, overwriting function pointers allows executing
>>   arbitrary existing code and programs frequently have enough
>>   capabilities that the word "existing" is not a serious
>>   limitation to determined attacker.
>>   AFAICS biggest trouble is due to caches: writes go to data cache,
>>   code is fetched from instruction cache and at least L1 caches
>>   are separate.  So there is synchronization overhead, but that
>>   should be managable.
> 
> Machines that separate code and data are still perfectly able to use
> techniques like just-in-time compilation; the same technique is used
> as is needed for such a simple thing as loading a program from the
> disk. Make an OS call to flip the usage of the memory area involved.

One things is trampolines on the stack.  That is useful technique
that requires executable stack.  Another thing is performance of
system calls to change permissions.  IIUC on modern machines that
is rather costly operation.  Of course, there is some inherent
cost for dynamically generated code, but generating say 200
instructions can be reasonably fast.  Hardware also can
adjust things like branch predictors relatively fast.  So
main performace bottlneck is cache synchronization (IIUC
at least some machines do this via complete flushing of
instruction cache which is gross) and adjustment of
permissions (which due to Spectre is likely to lead to
full cache flush).

> Separating code and data is an obstacle to naively coding the way
> people used to on a 360; I wasn't claiming that it was a crippling
> obstacle to such a commonly used technique.
> 
> John Savard

-- 
                              Waldek Hebisch
Technical Details
Message-ID: <11cqs4r$3hsr6$1@paganini.bofh.team>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
References: <6af0853c.2944265@news.eternal-september.org> <11cq61r$3gjce$1@paganini.bofh.team> <6af0b9a6.16362578@news.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.arch
Subject: Re: A Fatal Concertina Flaw?
Date: Sun, 8 Nov 2026 22:12:45 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11cqs4r$3hsr6$1@paganini.bofh.team>
References: <6af0853c.2944265@news.eternal-september.org> <11cq61r$3gjce$1@paganini.bofh.team> <6af0b9a6.16362578@news.eternal-september.org>
Injection-Date: Sun, 8 Nov 2026 22:12:45 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3732326"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2