{"id":92,"date":"2013-01-29T17:59:00","date_gmt":"2013-01-29T23:59:00","guid":{"rendered":"http:\/\/tommysprinkle.com\/mvssp\/?p=92"},"modified":"2013-05-27T15:00:39","modified_gmt":"2013-05-27T20:00:39","slug":"svc-screening-propagation","status":"publish","type":"post","link":"https:\/\/tommysprinkle.com\/mvssp\/2013\/01\/29\/svc-screening-propagation\/","title":{"rendered":"SVC Screening Propagation"},"content":{"rendered":"<p>We now have SVC screening working but only for one task (TCB).\u00a0 If we attach a subtask the SVC screening fields are not propagated to the new task.\u00a0 In later versions of MVS there is an option to set an additional flag in the TCB that will cause ATTACH processing to copy the SVC screening related fields.\u00a0 We could modify the ATTACH SVC routine to propagate these fields, in fact it would be pretty simple.\u00a0 Instead we will take a more interesting, and complex way to solve this problem.\u00a0 We will use SVC screening to intercept ATTACH SVC calls and propagate the SVC screening fields in our intercept routine.<\/p>\n<pre>         MVI   42(R2),X'00'       INTERCEPT SVC 42  ATTACH<\/pre>\n<p>First we set the corresponding byte in our screen table for SVC 42 (ATTACH).<\/p>\n<pre>         CLI   0(R9),42           ATTACH \r\n         BE    SVC42<\/pre>\n<p>In our intercept routine we check for SVC 42 and branch to process it.<\/p>\n<pre>SVC42    DS    0H                                       \r\n         LR    R14,R11            RESTORE RETURN ADDRESS\r\n         L     R6,=V(SVX42)       SVC 42 ROUTINE        \r\n         BR    R6                 TRANSFER CONTROL<\/pre>\n<p>First we restore the return address to register 14 and then we load the address of our SVC 42 processing routine into register 6 and branch to it. Entry to our routine will be exactly like a SVC call entry.<\/p>\n<pre>SVX42    CSECT ,                                         \r\n         USING SVX42,R6           ESTABLISH BASE REGISTER\r\n         USING TCB,R4             MAP TCB                \r\n         USING RBSECT,R5          MAP RB<\/pre>\n<p>We start by establishing a base register and mapping the TCB and RB control blocks.<\/p>\n<pre>         LR    R8,R14             SAVE RETURN ADDRESS  \r\n         LR    R9,R1              SAVE PARM LIST       \r\n         LR    R10,R15            SAVE ATTACH PARM LIST<\/pre>\n<p>Next we save the return address contained in register 14, the parameter list for the attached program contained in register 1, and the parameter list for the ATTACH SVC contained in register 15.<\/p>\n<pre>         MODESET EXTKEY=RBT234,WORKREG=2  GET CALLERS PROT KEY<\/pre>\n<p>Now we need to get into the storage protect key of the issuer or the SVC. For this we use the MODESET macro and specify EXTKEY=RBT234 indicating the SVC is a type 2, 3, or 4. We also specify register 2 is to be used as a work register.<\/p>\n<pre>         GETMAIN R,LV=ATLSTSIZ+4,SP=229              \r\n*                                                    \r\n         LR    R7,R1              POINT TO WORK AREA \r\n         USING ATTCHLST,R7<\/pre>\n<p>Now we getmain some storage to make a copy of the ATTACH parameter list. This is necessary because we will copy the parameter list and modify it before reissuing the SVC. We add four additional bytes to be used by our intercept routine. The allocated storage will be in the same key as the issuer of the SVC. The copy of the parameter area is pointed to by register 7.<\/p>\n<pre>         MVI   ATTCHLST+ATLSTSIZ,X'00'   RESET AUTH SWITCH     \r\n*                                                              \r\n         TESTAUTH FCTN=1,STATE=YES,KEY=YES,RBLEVEL=2           \r\n*                                                              \r\n         LTR   R15,R15             IS CALLER AUTHORIZED        \r\n         BNZ   AUTH010             NO - BRANCH                 \r\n*                                                              \r\n         OI    ATTCHLST+ATLSTSIZ,X'80'   SHOW CALLER AUTHORIZED\r\nAUTH010  DS    0H<\/pre>\n<p>We will need to know if the issuer of the SVC is APF authorized or not. First we set our flag byte, past the end of the parameter list, to zero indicating the caller is not authorized. Next we use the TESTAUTH macro to determine if the caller was APF authorized. We have the TESTAUTH routine check the JSCB APF authorization bit as well as checking for supervisor state and PSW protect key less than eight. If any of these conditions are true the caller is considered authorized and we set our flag bit.<\/p>\n<pre>         MVC   0(ATLSTSIZ,R7),0(R10)    COPY CALLERS PARM LIST<\/pre>\n<p>Now we make a copy of the ATTACH parameter list.<\/p>\n<pre>        \r\n         TM    ATTCHLST+ATLSTSIZ,X'80'  IS CALLER AUTHORIZED           \r\n         BO    AUTH020                  YES - BRANCH                   \r\n***********************************************************************\r\n*                  RESET ALL AUTHORIZED PARAMETERS                     \r\n***********************************************************************\r\n         NI    ATINDS,255-(ATJSTCB+ATMODE+ATSVAREA+ATKEY+ATDISP+ATJSCB)\r\n         NI    ATFLAGS1,255-ATRSAPF                                    \r\n         XC    ATJSCBA,ATJSCBA                                         \r\n         XC    ATTNSHLV,ATTNSHLV                                       \r\n         XC    ATTID,ATTID                                             \r\n         B     AUTH030             ATDISP ONLY VALID IF APF AUTH       \r\n*                                                                      \r\n*                                                                      \r\nAUTHO20  DS    0H                                                      \r\n         TM    ATINDS,ATDISP       WAS NO DISP SPECIFIED               \r\n         BNO   AUTH030             NO - BRANCH                         \r\n*                                                                      \r\n         OI    ATTCHLST+ATLSTSIZ,X'40'   REMEMBER NO DISP              \r\nAUTH030  DS    0H<\/pre>\n<p>If the caller is not APF authorized we clear all of the flags that are only valid for authorized callers and are ignored otherwise. If the caller is authorized we check to see if the ATDISP flag was set indicating the TCB should not be automatically made dispatchable. This is done because we will force this bit before reissuing ATTACH.<\/p>\n<pre>         OI    ATINDS,ATDISP      FORCE NO DISPATCH<\/pre>\n<p>Now we set the ATDISP flag in our copy of the ATTACH parameter list. Setting this flag bit will make the TCB initially marked non-dispatchable. This is necessary to allow us to set the SVC screening fields in the new TCB before be begins execution.<\/p>\n<pre>         SPKA 0                   GET INTO KEY ZERO            \r\n         NI   TCBFLGS7,255-TCBSVCS  TURN OFF SVC SCREENING     \r\n         MODESET EXTKEY=RBT234,WORKREG=2   BACK TO CALLERS KEY \r\n*                                                              \r\n         LR   R15,R7              OUR UPDATED ATTACH PARM LIST \r\n         LR   R1,R9               CALLERS R1                   \r\n         SVC  42                  ATTACH                       \r\n         LR   R11,R1              SAVE NEW TCB ADDRESS         \r\n         LR   R12,R15             SAVE RC<\/pre>\n<p>Now we get ready to reissue the ATTACH SVC. First we get back into protect key zero. Next we turn off SVC screening for the current TCB so we will not reintercept the call. We then get back into the caller&#8217;s protect key using MODESET. We restore the parameter registers 1 and 15 before call SVC 42. We then save the return parameter register values so they can be returned to our caller later.<\/p>\n<pre>         SPKA  0                  BACK TO KEY ZERO                 \r\n         OI    TCBFLGS7,TCBSVCS   TURN SVC SCREENING BACK ON       \r\n         LR    R1,R11             RESTORE PARM                     \r\n         LTR   R15,R12            CHECK RC                         \r\n         BNZ   FREEEXIT           EXIT IF NOT ZERO                 \r\n*                                                                  \r\n         L     R1,TCBSVCA2        GET SCREEN TABLE ADDRESS         \r\n         DROP  R4                                                  \r\n         USING TCB,R11            MAP NEW TCB                      \r\n*                                                                  \r\n         ST    R1,TCBSVCA2        STORE SCREEN TABLE ADDR INTO TCB \r\n         OI    TCBFLGS7,TCBSVCS   TURN ON SVC SCREENING<\/pre>\n<p>Now we go back to key zero and restore SVC screening for the current TCB. We then check the return code to see if the ATTACH was successful. If it failed we can to clean up and exit. If it was successful we copy the screen table address from the current TCB into the newly created TCB and set the TCBSVCS flag to active screening.<\/p>\n<pre>          L    R15,0(,R11)        POINT TO RB FOR NEW TASK \r\n          LM   R0,R3,RBGRSAVE     COPY REGISTERS TO NEW RB \r\n          STM  R0,R3,RBGRSAVE-RBSECT(R15)                  \r\n          LM   R0,R3,RBGRSAVE+16                           \r\n          STM  R0,R3,RBGRSAVE-RBSECT+16(R15)               \r\n          LM   R0,R3,RBGRSAVE+32                           \r\n          STM  R0,R3,RBGRSAVE-RBSECT+32(R15)<\/pre>\n<p>Now we copy the register contents from request block into the RB for the newly created task. This will make the initial register contents of the new task appear the same as if we had not intercepted the ATTACH SVC. It really should not make any difference since contents of the registers other than 1, 13, 14, and 15 are not guarenteed to contain any specific values. Still, by copying the contents of registers 0 through 12 we stay complete compatable with the normal operation of ATTACH.<\/p>\n<pre>         TM    ATTCHLST+ATLSTSIZ,X'80'   IS CALER AUTH            \r\n         BO    AUTH040                   YES - NO RESET NEEDED    \r\n*                                                                 \r\n         L     R1,TCBGRS12        GET SVRB ROUTINE R12            \r\n         NI    8(R1),255-X'80'    INDICATE ATTACHING TASK NOT AUTH<\/pre>\n<p>We have some attitional cleaup to do. Since we always reissue the ATTACH SVC and since we are always in supervisor mode when we reissue the SVC, ATTACH processing always sets up the new TCB as though it was created by an authorized program. This will cause problems when the new TCB is dispatched. If the caller is not authorized we need to reset a flag bit that is passed to the second half to ATTACH processing. When the new TCB is dispatched the initial execution point is in the ATTACH SVC where a new save area is allocated before passing control to a special entry point in the program loader. The program loader checks this flag bit to know if the caller of ATTACH was authorized or not. Since we reissued the ATTACH SVC this bit is always set. Here we reset it to reflect the state of the caller of the original SVC.<\/p>\n<pre>         SLR   R1,R1              ZERO R1                  \r\n         ICM   R1,B'0111',ATSTAIXT  ANY STAI\/ESTAI         \r\n         BZ    AUTH040              NO - SKIP              \r\n*                                                          \r\n         L     R1,TCBSTAB         POINT TO SCB CHAIN       \r\nAUTH035  DS    0H                                          \r\n         ICM   R1,B'0111',1(R1)   POINT TO NEXT ENTRY      \r\n         BZ    AUTH040            EXIT IF SCB NOT FOUND    \r\n*                                                          \r\n         USING SCB,R1                                      \r\n*                                                          \r\n         CLC   SCBEXIT+1(3),ATSTAIXT  IS THIS OUR SCB ENTRY\r\n         BNE   AUTH035                NO - TRY NEXT        \r\n*                                                          \r\n         NI    SCBFLGS2,255-(SCBSUPER)  TURN OFF SUPER BIT \r\nAUTH040  DS    0H<\/pre>\n<p>We have one last thing to clean up before we can let the new TCB dispatch. If a STAEI\/ESTAI was specified on the ATTACH we need to reset the supervisor mode bit in the STAE Control Block (SCB) if our caller was not authorized. Failre to properly set this bit could allow an unauthorized program to receive control in authorized mode when the ESTAE exit is called. If a STAEI\/ESTAEI exit was specified on the ATTACH we loop through the SCB chain to locate the associated SCB and clear the SCBSUPER bit.<\/p>\n<pre>         TM    ATTCHLST+ATLSTSIZ,X'40'  SHOULD WE LEAVE NON-DISP \r\n         BO    AUTH050                  YES - BRANCH             \r\n*                                                                \r\n         STATUS RESET,ND,(R11),(12)                              \r\nAUTH050  DS    0H<\/pre>\n<p>Now unless the caller was authorized AND specified the new task should not dispatch we now issue the STATUS macro to reset the task dispatchability status. This will allow the newly created task to begin execution.<\/p>\n<pre>FREEEXIT DS    0H                                             \r\n         DROP  R11                                            \r\n         USING TCB,R4                                         \r\n         MODESET EXTKEY=RBT234,WORKREG=2  GET INTO CALLERS KEY\r\n*                                                             \r\n         FREEMAIN R,LV=ATLSTSIZ,A=(R7),SP=229                 \r\n*                                                             \r\n         SPKA  0                  BACK TO KEY ZERO<\/pre>\n<p>Now all that is left is to clean up before exiting. First we use MODESET to get back into the caller&#8217;s key so we can FREEMAIN the work area we previously allocated with GETMAIN. We then go back to key zero.<\/p>\n<pre>         LR    R1,R11             SET TCB ADDRESS        \r\n         LR    R15,R12            SET ATTACH RC          \r\nSVCEXIT  DS    0H                                        \r\n         SPKA  0                  GET INTO KEY ZERO      \r\n         LR    R14,8              RESTORE RETURN ADDRESS \r\n         BR    R14<\/pre>\n<p>Before exiting we need to restore the return values for register 1 and 15 that were previously saved.<\/p>\n<pre>         IKJTCB ,   \r\n         IKJRB ,    \r\n         IEZATTCH , \r\n         IEZJSCB ,  \r\n         IHASCB ,<\/pre>\n<p>The control block mapping macros and register equates (not shown here) complete the SVC 42 intercept code.<\/p>\n<pre>         ATTACH EP=IFOX00,ECB=ECB                                     \r\n         ST    R1,PTRTCB          SAVE TCB ADDRESS \r\n         WAIT  1,ECB=ECB                           \r\n         DETACH PTRTCB            DETACH TCB<\/pre>\n<p>Now if we replace the LINK=IFOX00 to an ATTACH we can test the SVC 42 intercept logic.<\/p>\n<pre>JOB 6912  $HASP373 RUNSVX   STARTED - INIT 12 - CLASS A - SYS TCS3\r\nJOB 6912  20.04.34   0.00.00   0.00.00  0000   RUNSVX    COMPRESS \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IHARB                    \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IKJRB                    \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IEZXRB                   \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IEZBITS                  \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IKJTCB                   \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 TESTAUTH                 \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IHBERMAC                 \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 WTO                      \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IHBINNRA                 \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 DETACH                   \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 WAIT                     \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 ATTACH                   \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 IHBOPLST                 \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 GETMAIN                  \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 MODESET                  \r\nJOB 6912  SVC 18 R0=00096C68 R1=FFF69718 SAVE                     \r\nJOB 6912  20.04.34   0.00.00   0.00.00  0000   RUNSVX    ASM     \r\nJOB 6912  20.04.34   0.00.00   0.00.00  0000   RUNSVX    ########\r\nJOB 6912  $HASP395 RUNSVX   ENDED<\/pre>\n<p>Upon execution we see that SVC 42 was intercepted and SVC screening was propagated since we are still intercepting the FIND SVC calls.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We now have SVC screening working but only for one task (TCB).\u00a0 If we attach a subtask the SVC screening fields are not propagated to the new task.\u00a0 In later versions of MVS there is an option to set an additional flag in the TCB that will cause ATTACH processing to copy the SVC screening &#8230;<\/p>\n<p><a href=\"https:\/\/tommysprinkle.com\/mvssp\/2013\/01\/29\/svc-screening-propagation\/\" class=\"more-link\">Continue reading &lsquo;SVC Screening Propagation&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[15,20,18,17,21,16,19],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-svc-screening-propagation","tag-attach","tag-estai","tag-modeset","tag-rb","tag-status","tag-tcb","tag-testauth"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3x7AW-1u","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":6,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/posts\/92\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tommysprinkle.com\/mvssp\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}