Consider an underlay cognitive radio network where an eavesdropper (Eve) targets to intercept the information exchanging between the primary nodes. The secondary system is allowed to access the licensed spectrum as long as it does not violate the target quality-of-service (QoS) of the primary network. In return, the secondary network also assists the primary network against the malicious attack of the Eve. The authors aim at designing a resource allocation algorithm maximising the secrecy rate of the primary system while also satisfying the QoS requirement of the secondary system. To be more precise, a jamming noise accompanied by the information signal to degrade the Eve's channel and the information beamforming vector at the secondary transmitter is jointly optimised. The problem of interest is formulated as a non-convex optimisation problem. For the case in which global channel state information (CSI) is available, the authors propose a path-following algorithm which aims at locating a Karush-Kuhn–Tucker solution to the original non-convex program. By novel transformations and approximations, the authors arrive at only a simple convex problem of moderate dimension. For the case in which only statistics of the Eve's CSI are available, the authors reformulate the considered problem by replacing a non-convex probabilistic constraint with a set of convex constraints. A worst-case scenario for a secure communication, where an optimal linear decoder is used at the Eve, is also considered. The superior performance of the proposed design is revealed by numerically comparing it with other known solutions.